3

As we know, there are few versions of ArcGIS (9.x,10) and Python(2.x,3.x) are in use. Issues are facing when we run scripts/toolbox of arcgis since the script written in one version of python and the python installed with arcgis is different version.

  1. How to identify python script version so that we can directly execute and save time?
  2. How to convert the existing python script to the installed python version on the system and get result without hassle of programming?
  3. Is there any procedure for ArcGIS to take python version 2/3.x as default so that, we can install multiple versions of python and change default version to run according to our requirement?
1
  • 1
    What's the use case for having that many versions of Python installed on one system? Why don't you just support a single version? All Python scripts written for 9.3 will continue to work in 10.0 and 10.1, so a long as you develop against the lowest common denominator you should be fine. Commented Mar 26, 2012 at 0:19

2 Answers 2

8

Every version of ArcGIS requires a specific Major.Minor version of Python (it uses the official installer releases from python.org). That version will be documented in the help. 9.3.X uses Python 2.5, 10.0 uses 2.6, 10.1 uses 2.7. Since the stack is compiled against a specific binary version of Python, other versions of Python will fail to load arcgisscripting and nothing will work.

You can use sys.version_info tuple to determine the Python version at runtime.

1
  • 2
    e.g., use sys.version_info[:2] >= (2, 5) to test if it is Python 2.5 or later
    – Mike T
    Commented Mar 26, 2012 at 4:42
6

1) There's no such thing as a script version, but there is a standard for defining package requirements for a Python interpreter version. See PEP 345: http://www.python.org/dev/peps/pep-0345/.

2) Search for "2to3". It does not remove the "hassle" of programming.

3) In Python programming, we use virtualenv to juggle interpreters and specific sets of packages. I don't know if ArcGIS supports such virtual environments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.