Python compiled file(.pyc) run issue in ArcGIS 10.0, 10.2, 10.3

4381
5
12-07-2015 03:17 AM
MonirRahman
New Contributor II

I have developed an arcgis 10.0 based addin with .NET technologies. I have run python script from my .NET code. In acrgis 10.0 , python script compiled with python version 2.6. I have also another 2 machines where arcGIS 10.2 and  acrgis 10.3 installed. These 2 machines have python version 2.7.  If I build my code in each machine and run tool in arcGIS, then all functions are OK. But the problem is :

# If I build my code and compiled with python version 2.6 , it does not work in arcgis version 10.2,103 (>10.0). It gives a run time error: >>Runtime Error: bad magic number in .pyc files.<<

How to resolved this problem so that I can build in machine which installed arcgis version 10.0 and works good to all other version like 10.2,10.3 with python compiled file ...

0 Kudos
5 Replies
DanPatterson_Retired
MVP Emeritus

if you are using imports, just check the version number in your code.  And why not just distribute the py script version 3.4 will work in older versions unless something has changed or isn't supported.

>>> import sys
>>> sys.version
'3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AMD64)]'
>>> sys.version_info
sys.version_info(major=3, minor=4, micro=1, releaselevel='final', serial=0)
>>>

pyc scripts are checked at runtime

http://stackoverflow.com/questions/15839555/when-are-pyc-files-refreshed

FreddieGibson
Occasional Contributor III

Is there a particular reason why you're using the pyc files? Without using those an addin created in 10.0 would be forward compatible with any higher 10.X release.

MonirRahman
New Contributor II

Thanks for your reply. I have done a particular function using python script. That's why I need pyc files.

0 Kudos
LukeWebb
Occasional Contributor III

The Answer is to just use .py files.

There is no need I know where a pyc is required, or difference between using a .py or .pyc   -- apart from a tiny (insignificant) speed boost at loading a pyc.

If you are doing GIS, any GIS task will cost 1000x more than compiling a .py file, you are wasting your time if you are doing this for performance reasons.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Of course, you saw the Stack post on magic numbers and deleting pyc files on your cross-post

Python compiled file(.pyc) run issue in ArcGIS 10.0, 10.2, 10.3 - Geographic Information Systems Sta...