Select to view content in your preferred language

32-bit and 64-bit Python 2.7 on the same machine

15511
12
Jump to solution
09-13-2012 10:53 AM
ChanningDale
Occasional Contributor
Hello all,

I have installed on a Windows Server 2008 R2 virtual machine ArcGIS for Desktop 10.1 and ArcGIS for Server 10.1.  The desktop install came with the 32-bit version of Python 2.7, and the server install came with the 64-bit version.  I seem to now have a conflict between both versions when I try to work with Python on ArcGIS for Desktop.  I've run into this before with Desktop when I had two different versions of Python on my computer, and the way that I solved it was to keep one and uninstall the other.  In this case, I feel like I wouldn't be able to uninstall either of them, since both pieces of software probably rely on arcpy for certain functions.

Here's the error I get when I try to run my script in the shell and it initially tries to import the arcpy module:

Traceback (most recent call last):
  File "C:\Projects\11047\DATARE~1\Toolbox.pyt", line 1, in <module>
    import arcpy
  File "c:\program files (x86)\arcgis\desktop10.1\ArcPy\arcpy\__init__.py", line 21, in <module>
    from arcpy.geoprocessing import gp
  File "c:\program files (x86)\arcgis\desktop10.1\ArcPy\arcpy\geoprocessing\__init__.py", line 14, in <module>
    from _base import *
  File "c:\program files (x86)\arcgis\desktop10.1\ArcPy\arcpy\geoprocessing\_base.py", line 14, in <module>
    import arcgisscripting
ImportError: DLL load failed: %1 is not a valid Win32 application.

Has anyone else come across this problem?  I think I need to change the version that my Python Shell is using, since at the top of the window it says 64 bit (AMD64), but since I'm developing in Desktop, it should probably be 32 bit (Intel 32).  I was able to develop my script, and then today I started to run into this error.

Thanks!
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ChrisFox3
Frequent Contributor
Ok, I think I got it. It seems to just be a file associations issue. If I install Desktop first then Server, I am finding that launching IDLE from the 32 bit install location, C:\Python27\ArcGIS10.1\Lib\idlelib will load IDLE with the 64 bit version of python. This is because when you install the 64 bit version of python last the file association for .py and .pyw files becomes C:\Python27\ArcGISx6410.1\pythonw.exe. So when you double-click the idle.pyw it is executed using the 64 bit pythonw.exe. So you just need to modify the default file associations of .pyw to point to C:\Python27\ArcGIS10.1\pythonw.exe.

Alternatively you can see the same from command line:

C:\>C:\Python27\ArcGIS10.1\pythonw.exe C:\Python27\ArcGIS10.1\Lib\idlelib\idle.pyw (Opens IDLE with 32 bit version of python)

C:\>C:\Python27\ArcGISx6410.1\pythonw.exe C:\Python27\ArcGIS10.1\Lib\idlelib\idle.pyw (Opens IDLE with 64 bit version of python)

View solution in original post

0 Kudos
12 Replies
ChrisFox3
Frequent Contributor
You should have 2 different versions of IDLE installed as a result as well. The one that you will find in the shortcut from Start > All Programs > ArcGIS > Python 2.7 will correspond to the last one you installed, in this case it seems Server and the 64 bit version.

You could go directly to the 32 bit version and launch IDLE by double-clicking the file, most likely located at:

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

Should could add a shortcut to this or update the current shortcut in the start menu by opening the You could also right-click Idle from the Start Menu and open its properties to adjust which version it is pointing to.
0 Kudos
ChanningDale
Occasional Contributor
Thanks for your reply, Chris.

I went to the IDLE in the ArcGIS 10.1/Python 2.7 folder in the Start menu, and the paths to the python.exe and ILDE were referencing the 64-bit version, so I changed both paths.  When I open the IDLE from there, the Shell is now using the 32-bit Python.

Now, I don't know if this makes a difference, but I'm developing my tool through a new Python toolbox, and this is where I'm running into the issue.  In the Geoprocessing menu, I had already set the script tool editor to use the 32-bit IDLE before I ran into this error.  Even though that path is pointing to the 32-bit version of the IDLE, I still see 64-bit referenced in the Shell when I edit the toolbox and try to run the tool.  I tried creating a new Python toolbox, and even the default code doesn't run and I get the same error.

If I read the stack trace right, it looks like when the tool tries to import the arcpy module from the Desktop program files, it fails, which made me assume that the 64-bit Python was causing a problem.

Any more thoughts?
0 Kudos
ChrisFox3
Frequent Contributor
A couple things, I don't know why if you have pointed the editor and debugger to the 32 bit installation of IDLE in the Geoprocessing options why it would open the 64 bit installation. I might recommend you just try to clear out the path and reapply it again.

Also when you say you run the tool and get the error do you mean if you run the tool from IDLE after you click to edit the python toolbox, or do you also get the exception in ArcMap or ArcCatalog? I would think if an exception was raised while importing arcpy you would see a red X on the toolbox in ArcCatalog and you wouldn't be able to double-click to open the tool. Are you able to run the tool from the application? Are you only seeing this problem if you try to run the tool from the IDE?
0 Kudos
ChanningDale
Occasional Contributor
I tried clearing out the Editor path and then navigate to the 32-bit version again, but it still doesn't reference the correct one.

I get the error when I'm editing the Python toolbox in ArcCatalog with the IDLE.  There is a red "X" displayed on the toolbox, so I can't see the tool and click it to run it.
0 Kudos
ChrisFox3
Frequent Contributor
If you type "import arcpy" in the python window in ArcMap or ArcCatalog do you get the same exception.

Could you go to start > run and type regedit and click ok.

Then browse to:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ESRI\Python10.1, what is the value for PythonDir?

Also:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\InstallPath, what is it's value?
0 Kudos
ChanningDale
Occasional Contributor
The PythonDir value is C:\Python27\

The InstallPath value is C:\Python27\ArcGIS10.1\

Should they be the same?
0 Kudos
ChrisFox3
Frequent Contributor
No that is right. So do you get an error if you import arcpy in the python window from ArcMap or ArcCatalog? If you right-click a folder in Catalog and go to New > Python Toolbox does it display with a Red X without making any changes to the code?
0 Kudos
ChanningDale
Occasional Contributor
I'm seeing this error only when I open the IDLE through either ArcCatalog or ArcMap.  I opened the Python windows in ArcCatalog and ArcMap and didn't see any errors when I type in "import arcpy" and hit enter.

Also, no red "X" appears when I create a new Python toolbox.  Yet, if I try to run the default code, that same error comes up in the IDLE.  No red "X" after running the default code either.
0 Kudos
ChrisFox3
Frequent Contributor
Ok thats good, it is a little bit clearer now ArcGIS Desktop is using the right version of Python. The problem just comes down to why even though you have set the Editor in the Geoprocessing Options to the 32 bit version of IDLE is it opening the 64 bit version when you right-click the Python Toolbox and select Edit? I don't really know the answer to that, you could log a new incident with Tech Support and we could try to troubleshoot it.

You might also try installing another Python IDE like PythonWin or PyScripter and pointing it to one of those IDEs to see if it makes a difference. Until you are able to resolve it you could always open the 32 bit version of IDLE from your desktop and browse and open the .pyt file from disk, rather than launching it from Catalog.
0 Kudos