Multiple versions of Python

7619
7
11-05-2014 11:33 AM
GeorgeSinkinson
New Contributor

I'm looking for recommendations on how to handle multiple versions of Python on a single machine.

I have ArcGIS 10.2.1 for Desktop installed on a Windows 8.1 machine.

The installation of ArcGIS set up Python in C:\Python27\ArcGIS10.2.

The Readme indicates this is Python version 2.7.5

I'd like to use Python version 3.4.2 for some non-ArcGIS applications.
I'm assuming the install would set up in something like C:\Python34

I'm looking for help on several things:

     - some rational directory structure approach and naming
     - what to do with the scripts in C:\Python27\ArcGIS10.2\Tools

I don't want to compromise the ability to use Python with ArcGIS but
I don't have any idea if all the version 2 scripts are still valid in version 3.

I don't know if I need to keep both versions, but if so, how would I control
which version is invoked? Currently there isn't any Python entry in my
PATH statement.

Yes, obviously a 'newbie', but I'd like to start off in the right direction ...

0 Kudos
7 Replies
DanPatterson_Retired
MVP Emeritus

My recommendation is to stick with the 2.7.x version associated with ArcMap 10.x.x unless you have a real compelling reason to run python 3.x (just to explore in my mind is not compelling enough).  It can be done...I just don't recommend it unless you are good at the whole path/default/registry thing or...unless you have a separate machine to install it on

GeorgeSinkinson
New Contributor

Dan,

Thanks for taking the time to reply. And your words of caution.

Having just jumped from Win XP to 8.1, I understand your point,

but I guess we need to keep moving forward rather than get run over

from behind ...

0 Kudos
curtvprice
MVP Esteemed Contributor

Yes, Python 3 will install in its own folder.

You probably want to just make sure the Windows file associations continue to link .py and .pyc files to the older version of Python by default, and launch your python 3 scripts explicitly. You may have to change them back if you want Python 2.x to continue to be the default.

ArcGIS seems to keep track in the registry which Python it uses so I haven't had big problems with that.

Python 3 has a new feature called the Launcher that allows you to get around the limitations of Windows file associations, for example, you can add a "shebang" line

#! python3

which will make Python scripts always run in 3.

You may want to look into installing ArcGIS Pro pre-release, which includes a Python 3.4.1 installer set up to be able to install Pro's 3.4-compatible arcpy.

How do you get Python 3.4 to see ArcGIS Pro arcpy?

You can get a start on making sure your scripts will be 3.x compatible by including this line near the top of your scripts that you are running at 2.x:

from __future__ import print_function

GeorgeSinkinson
New Contributor

Curtis,

Thanks for your reply. I wanted to be sure I had not missed some great screaming reason NOT to give it a shot.

Your note makes me feel a lot better going forward with 3.x.

Thanks

0 Kudos
EliseAcheson
New Contributor

Does anyone have a good setup figured out for this? With Python 3.x installed somewhere, but python 2.7.5 (e.g. with ArcGIS 10.2.2) also running fine within ArcGIS Desktop?

Python 3.x seems to have many advantages like built-in pip, better treatment of unicode, and so on.

thanks

0 Kudos
by Anonymous User
Not applicable

Take a look at Anaconda: https://www.continuum.io.  I've had it installed for years and have multiple different python environments (~12) for different applications.  I've never had it cause problems with the ESRI included python distribution.  Every environment is completely separate.  The conda package manager, part of anaconda, is now even included with ArcGIS Pro 1.3.

IMPORTANT: To avoid breaking ArcGIS (or other software), during the installation of Anaconda uncheck the checkboxes  (a) make Anaconda the default Python and (b) add Anaconda's Python to the PATH.

Another option would be to use virtualenv (Virtualenv — virtualenv 15.0.2 documentation ) to create new virtual environments but it seems like conda is prefered at least in the scientific community lately.

Some links with using anaconda with arcgis desktop.

Using Anaconda modules from the ESRI python environment (All Users) - USGS OEI/Enterprise GIS - myUS...

Connecting Arcpy to Your Jupyter Notebook

Good luck!

Sage

EliseAcheson
New Contributor

Hi, thanks a lot for the suggestion. Actually that is exactly what I was doing this morning before I saw your reply.

It is working great so far!

Some details:

- I have Anaconda installed (comes with Python 3.5, 64-bit option for Windows on the downloads page) at C:/Anaconda3

- that python executable is in C:/Anaconda3/python.exe and runs python 3.5, and I can import packages for python 3.5 via typing in a console "conda install package-name" (this will go to the default anaconda environment, at the moment I only have one)

- when I launch python command the way I used to (e.g. Windows icon > "python (command line)"), it shows python version 2.7.5 running (this came with ArcGIS 10.2.2), and just to confirm it's using the right libraries, if I type "import os", then "os.path", it shows where that module is: <module 'ntpath' from 'C:\Python27\ArcGISx6410.2\lib\ntpath.pyc'>, this is actually the 64-bit running

- I can launch ArcMap, choose 'Python' under Geoprocessing, to open the Python window, and do as above with import os etc. (this one is actually using the 32-bit python in my case).

So, all is well so far. Note that during the install of anaconda, the dialog had the two questions Sage Wall mentions, with a slight modification, in that it actually asked: "make Anaconda the default Python 3.5", and not the "default Python", so I kept this box ticked, because the anaconda Python 3.5 is the only 3.5 Python that I have installed (the others are 2.7.5). No issues so far.

~elise