Select to view content in your preferred language

Is there an easy way to go back and forth between Python 32 and Python 64?

5154
9
07-15-2015 12:02 PM
MichaelSouffront
Deactivated User

I was just wondering this the other day. I moved to Python 64 background processing a while ago, but there are certain tools I want to use that still need Python 32.

I would like to keep Python 64 background processing but be able to go back to Python 32 every once in a while without having to uninstall 64.

Thanks,

Michael

9 Replies
DanPatterson_Retired
MVP Emeritus

I assume that you have ruled out a direct launch of each versions's *.exe ?

0 Kudos
MichaelVolz
Esteemed Contributor

How would you perform a direct launch of each version's exe?

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

How exactly are you running Python?  The interactive Python window in ArcGIS?  IDLE?  Stand-alone Python console?

0 Kudos
MichaelVolz
Esteemed Contributor

I am calling either a python script directly from Windows Task Scheduler or I am calling the python script from a bat file that is called from Windows Task Scheduler.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Notice the forked paths.  When ArcGIS 10.3 was installed, it wanted its own version of the various ways of starting 'python' in this example, IDLE.  Depending on your installation your Python27 or Python3X will have its own path, which may be supplemented with some reference to ArcGIS depending upon when in the sequence of installs, your flavor of python appeared.  It is worth while figuring out which version to use and whether you want ArcGIS involved or not.

C:\Python27\Lib\idlelib\idle.pyw

C:\Python27\ArcGIS10.3\Lib\idlelib\idle.pyw

JoshuaBixby
MVP Esteemed Contributor

If you are running stand-alone scripts from either Task Scheduler or a batch file, then you will want to focus on file type associations in Windows:  Change which programs Windows uses by default.  You will want to focus on "Associate a file type with a program."

The hard part about knowing which Python environment is associated with Python scripts (*.py) is that both are called "python.exe" so the information provided to the user is rather uninformative:

windows_py_file_type_association.PNG

You can use the "Browse" button to find the desired, i.e., 32- or 64-bit, python.exe.

I think a better way to handle the situation is to explicitly pick/set the Python environment when you are calling the script from the Task Scheduler or Command Prompt.  For example:

rem Relying on default file-type association
C:\>tmp\echo_python_version.py
2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)]

rem Explicitly using 32-bit Python
C:\>C:\Python27\ArcGIS10.3\python.exe tmp\echo_python_version.py
2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)]

rem Explicitly using 64-bit Python
C:\>C:\Python27\ArcGISx6410.3\python.exe tmp\echo_python_version.py
2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)]
FreddieGibson
Honored Contributor

If you're already executing the python script from task schedule using a batch file the easiest option would be to point to the python.exe you're needing to use.

For example,

32-bit python to execute arcpy from batch against Desktop

cd C:\Python\Python27\ArcGIS10.3
python Drive:\Path\To\Script.py <Arguments>

64-bit python to execute arcpy from batch against Desktop

cd C:\Python\Python27\ArcGISx6410.3
python Drive:\Path\To\Script.py <Arguments>

64-bit python to execute arcpy from batch against Pro

cd C:\Python\Python34
python Drive:\Path\To\Script.py <Arguments>

From the ArcMap UI you can handle this by requiring that some of your tools on run in the foreground (i.e. 32-bit). If the 64-bit background gp is installed then any tool run in the background would run in 64-bit.

While you're developing the python code I would suggest using a IDE that allows you to specify the python executable. This would be easier than having to worry about the consequences of messing with the file associations on the machine. I typically work with the paid version of WingIDE and it will allow you to easily switch the python executable. For production I typically either write up a batch command to hard code the version of python to run against or I use python to write the batch file and fire off a DOS command to execute the batch file. Hope this helps.

curtvprice
MVP Esteemed Contributor

Also --

I really like using python scripts as script tools from ArcGIS. For one thing, you can use all the nifty parameter validation which saves a lot of time. Also you don't  need to wait for arcpy to import every time you run your script - if you run the script "in process" it will use the arcpy ArcMap already imported. There are two options to control how script tools are run that affect 32/64 because only background processing is 64 bit:

1. Geoprocessing options - disable background processing, your script tool will run from 32-bit arcmap

2. Script tool properties - check the box "Always run in foreground" (foreground is 32 bit)

UlrichMerz
Deactivated User

If you want to use Python 32Bit, set PYTHONHOME to the appropriate python.exe-Path:

>set PYTHONHOME=C:\Python27\ArcGIS10.2

Installing Modules:

Change to the unpacked Module-Code:

eg:

>cd c:\Temp\Python27\setuptools-5.4.2

>C:\Python27\ArcGIS10.2\python.exe setup.py install

When installing with "pip install Module", run pip 32Bit:

C:\Python27\ArcGIS10.2\Scripts\pip.exe install Module

Running Python 32Bit:

>C:\Python27\ArcGIS10.2\python.exe yourcode.py

When you want to use Python 64Bit, set PYTHONHOME to the appropriate python.exe-Path:

>set PYTHONHOME=C:\Python27\ArcGISx6410.2

Installing Modules:

Change to the unpacked Module-Code:

eg:

>cd c:\Temp\Python27\setuptools-5.4.2

>C:\Python27\ArcGISx6410.2\python.exe setup.py install

When installing with "pip install Module", run pip 64Bit:

C:\Python27\ArcGISx6410.2\Scripts\pip.exe install Module

Running Python 64Bit:

>C:\Python27\ArcGISx6410.2\python.exe yourcode.py

Always install all Python-Modules in 32 and 64Bit: