Select to view content in your preferred language

Can't run python stand-alone since upgrading to 10.1

2408
10
06-14-2013 02:01 PM
ThomasDilts
Frequent Contributor
Hi,

I'm able to run scripts as tools in ArcToolbox but I can't seem to run them from IDLE directly since upgrading to 10.1.  Initially I had SP1 for background geoprocessing but have since rolled that back thinking that it might help.  The same problem occurs.  I get the following error in IDLE:

Python 2.7.3 |EPD 7.3-2 (64-bit)| (default, Apr 12 2012, 15:20:16) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>

Traceback (most recent call last):
  File "X:\for_tdilts\outbox\GIS_tools_scripts\ClimaticWaterDeficit\Version10_1\extras\DurCWD_normal.py", line 6, 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.
>>>

Is it that ArcGIS somehow is managing to point to 64 bit python but IDLE needs to be directed there?  Is there some sort of document with instructions that I need to be following for "post-install" of ArcGIS Desktop???

-Tom
Tags (2)
0 Kudos
10 Replies
V_StuartFoote
MVP Alum
Tom,

Let us see a dump of your environment. From a command prompt enter these commands:

where python

echo %PYTHONHOME%

echo %PATH%

dir C:\Python27


Stuart
0 Kudos
DanPatterson_Retired
MVP Emeritus
On a related issue, I uninstalled 10.0 and Python 2.6 and installed 10.1 and Python win compatable with 2.7.2 and Pyscripter and I am getting a "cannot import arcpy" error message.  Is there some registry issue??? are these problems related///
0 Kudos
V_StuartFoote
MVP Alum
Dan,

Yes I beleive they are related, and we could use a look at the same set of environment configurations.

Should we assume that your inprocess ArcGIS use of Python scripting is correct?

Stuart
0 Kudos
ThomasDilts
Frequent Contributor
Hi Stuart,

Thanks for your quick response.  I can't seem to get your commands to work.  I'm going to the command prompt, typing in "python" to get it to python, and then typing in "where python" I get the following error:

File "<stdin>", line 1
where python
SyntaxError: invalid syntax

-Tom
0 Kudos
V_StuartFoote
MVP Alum
Tom,

Sorry, I should have been clearer. Those are all Windows OS commands and utilities, just open a Windows command prompt (cmd.exe) window and enter each. Then copy & paste the result to a text editor to clean up for posting to the thread, or take a screen capture and post up the image. 

Can see already though from you post, that you are launching a 64-bit Python--that will cause problems with 32-bit ArcGIS for Desktop.

Stuart
0 Kudos
ThomasDilts
Frequent Contributor
Stuart,

where didn't work but the others did (see attachment).  A while back I had installed the 64-bit python 2.7 for another program that ran on python, and I guess I was thinking that the ArcGIS uninstall would have gotten rid of it and installed the 32-bit version over it.  Maybe the best solution would be to wipe python off my computer and re-install from scratch??

-Tom
0 Kudos
V_StuartFoote
MVP Alum
Tom,

You appear to be running a 64-bit Enthought Python Distribution, dtd 4-12-2012 as you default Python.

From your screen capture, the C:\Python27 directory listing contains a full Python distribution--python.exe, pythonw.exe which look by date to be the 64-bit EPD you show running in IDLE. Would likewise impact Python run from command prompt as your environment variables are pointing to that directory.

But you also have an Esri ArcGIS 10.1 installation done on 5-9-2013. When, since the C:\Python27 would not have been detected as a 32-bit python installation, the Esri ArcGIS installer laid down the 32-bit Python in C:\Python27\ArcGIS10.1--a look in that directory will show you probably have another python.exe and pythonw.exe installed. Fortunately the Windows registry, ArcGIS for Desktop registry settings keep it pointed to the correct Python executables where it reads the Desktop101.pth for proper path actions.

But since the system environment variables are pointing to the C:\Python27 directory, the 64-bit python is what is always being called from command prompt or Python IDE environment like IDLE.


[INDENT]To clean things up, you should simply be able to uninstall the Enthought Python Distribution Free 64-bit Python from Add/Remove programs (appwiz.cpl).

Then check your Environment variables to adjust the PATH value to reflect a path to "C:\Python27\ArcGIS10.1" and perhaps set a PYTHONHOME variable to "C:\Python27\ArcGIS10.1"

Your IDLE session, or a windows command line or system scripted launch of Python, will then run with the 32-bit pythonw.exe[/INDENT]


And, if you need 64-bit python, or want a packaged Python bundle like Enthought Canopy Express, you have to manage your environment adjusting it to use the appropriate versions. That would include use of Esri's ArcGIS 10.1 SP1 64-bit Desktop Background Geoprocessing installation when running it "out of process", i.e. without the ArcGIS Desktop GUI.

The 64-bit Desktop Background Geoprocessing installation replaces some 32-bit components of the ArcPy site library with 64-bit equivalents--and the ArcGIS for Desktop does not use the system environment variables to keep track of the executable to run while in-process. But when running scripts outside ArcGIS for Desktop GUI, you have to manage the path and working directories for your 32-bit or 64-bit Python scripting.

Hope that is clear enough for you, post back if not.

Stuart

P.S. not sure why your Windows 7 command line use of where.exe is not responding correctly with executable location, it should be.
0 Kudos
ThomasDilts
Frequent Contributor
Thanks Stuart,

This helps a lot, and your explanation is very clear.  I'm in the process of re-installing right now and will set the PATH and PYTHONHOME variables.  I had installed the Enthought for python and had forgotten that I had it on my computer.  Prior to uninstalling I had tried just changing the the PATH and PYTHONHOME variables, but that alone didn't end up doing the trick.  If I'm understanding what you're saying correctly if I want to run 64bit python for scripts outside of ArcGIS I should simply be able to change the PATH and PYTHONHOME variables temporarily to point them to the 64 bit version?

-Tom
0 Kudos
ThomasDilts
Frequent Contributor
I just wanted to mention that my scripts are working again.  Thanks so much for all of your help Stuart.
0 Kudos