Select to view content in your preferred language

Problem importing arcpy in ArcMap console -- 64 bit DLL conflict

13944
23
Jump to solution
03-05-2013 12:35 AM
JohnBurkhart1
Occasional Contributor
Hello,

Working on Windows 7 with ArcGIS 10.1 using the 64 bit geoprocessing python... I have been having problems with using python **inside** ArcMap. Outside of ArcMap, I can run the ArcGISx6410.1/python.exe without problems. Here is my WORKING case:

arcpython.bat which will launch 64 bit python and use 64 bit libraries/modules and wraps everything in Ipython.
@echo off set path=C:\Python27\ArcGISx6410.1;%path% set PYTHONPATH=C:\Python27\ArcGISx6410.1\Lib\site-packages\;C:\Python27\Lib\;C:\Python27\Lib\site-packages\;%pythonpath% C:\Python27\ArcGISx6410.1\python.exe -c "import sys; from IPython.frontend.terminal.ipapp import launch_new_instance; sys.exit(launch_new_instance())" %* exit /B %ERRORLEVEL%


With this, I get an Ipython window and all arcpy functionality with no errors.

However, when I launch the python console inside of ArcMap I get a traceback with the following ultimate error:
  File "C:\Python27\Lib\site-packages\numpy\lib\type_check.py", line 8, in <module>     import numpy.core.numeric as _nx   File "C:\Python27\Lib\site-packages\numpy\core\__init__.py", line 5, in <module>     import multiarray ImportError: DLL load failed: %1 is not a valid Win32 application. >>> 


So clearly, it's a problem with the 64 bit imports.

I have my PYTHONPATH set to point to my 64 bit libraries, and I've defined a pythonExePath to point to the ArcGISx6410.1/python.exe.

I'm stumped, because I don't understand how to control which python executable is called from **WITHIN** Arcmap. Output from the console only provides this:

>>> import sys >>> sys.executable  'C:\\Program Files (x86)\\ArcGIS\\Desktop10.1\\bin\\ArcMap.exe' >>> 


Please advise on how to instruct the console to use the ArcGISx6410.1/python.exe because that seems to be the problem...

Thanks,
john
Tags (2)
0 Kudos
23 Replies
ChrisSnyder
Honored Contributor
Were you able to figure out which specific PATH value was required to get you up and running? Surely not all of those...
0 Kudos
JohnBurkhart1
Occasional Contributor
Were you able to figure out which specific PATH value was required to get you up and running? Surely not all of those...


Not entirely sure, but from my tests (limited) it seems this is what was required:

1) 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.1\\arcpy',
to get 'arcpy' to import

2) 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.1\\bin',
to get pythonaddins to import

3) 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.1\\ArcToolbox\\Scripts'
to get some toolboxes / my custom Addin working

What I did was to remove all custom system env variables and start:
C:\\Python27\ArcGIS10.1\python.exe

Then I just did:
%import sys
%paths_to_set = sys.path

Using the paths_to_set list of strings, I made the startup script. I believe the most important point is to override the path settings that point to anything ArcGISx6410.1/...

--john
0 Kudos
JohnBurkhart1
Occasional Contributor
I want to say the steps you've taken are not normal.
On a brand new machine after you install Desktop, and 64-bit Background, thats it. No environment variables, no Python path settings, nothing like you've needed to do.

... it all just works.


If 'normal' means a 'vanilla' machine with no other Python installed, then no, my machine is not normal. I am highly experienced with Python programming, and my machine has multiple python installations and virtualenvs. I'm new to working with Arcpy.

While I'm extremely happy to see the adaptation of Python into ESRI's tools,from what I see the overall 'paradigm' of arcpy is not all that 'pythonic'. It's a great tool for scripting, but it feels more like a set of wrappers than an API. But I'm getting used to it 😉

Anyway, I think it's naive to think that those working with arcpy won't have other installations and PATH modifications already done on their machines.

To reproduce my setup... you could try to install 64bit python first, along with Ipython, numpy, scipy, and matplotlib... then make a custom PYTHONPATH setting to point to your own python script directory... maybe django also 🙂

Make sure you also point the PATH env variable to the django bin dir, and python scripts dir...

THEN, and only after the above... install Arcmap, then the 64 bit geoprocessing extension... maybe you'll be in the mess I am, and you'll find it doesn't "just work".

--john
0 Kudos
KevinHibma
Esri Regular Contributor
Interesting:

1) 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.1\\arcpy',
to get 'arcpy' to import

2) 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.1\\bin',
to get pythonaddins to import

3) 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.1\\ArcToolbox\\Scripts'
to get some toolboxes / my custom Addin working


Do you have a file "desktop10.1.pth" @ C:\Python27\ArcGIS10.1\Lib\site-packages ?
This Python path file which gets put down by Desktop has those 3 references. Since you've manually created those, it sounds like you might not have it.
The same exists @ C:\Python27\ArcGISx6410.1\Lib\site-packages for 64bit background, with a file called "DTBGGP64.pth"
0 Kudos
JohnBurkhart1
Occasional Contributor
Strange, as I do have those .pth files. Interestingly, I just googled around a bit to remind myself whether .pth or PYTHONPATH takes precedence. The funny thing is, I found the answer here:

http://forums.arcgis.com/threads/23230-quot-ImportError-No-module-named-arcpy-quot-PYTHON

Somehow I didn't find this thread when I searched earlier...

Funny, because it provides a lot of answers to my problems... principally, that my PYTHONPATH setting was/is indeed messing up the 32 bit console python. So, if I want to keep my PYTHONPATH with the ArcGIS64 references, then my 'hack' is a valid solution... so it seems.
0 Kudos
AlanStewart
Frequent Contributor
I seem to be having an issue similar to John, but everything on my machine is standard ESRI other than the installation of PythonWin. I have not odded anything to the PATH environment variable, or created PYTHONPATH or PYTHONSTARTUP environment variables. Registry keys for both the 32-bit and 64-bit versions of Python 2.7 look correct.

I need to publish a geoprocessing task to Server 10.1. I have installed:
- ArcMap 10.2 SP 1
- ArcGIS Server 10.1 SP1
- 64-bit background geoprocessing patch

I've enabled background geoprocessing. Since I assume 64-bit Python will be executed, I installed the latest 64-bit build of PythonWin.

I'm starting my script by right-clicking on it in the ArcToolbox and selecting 'Debug...'. PythonWin prints the following first line:

PythonWin 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32.

The first few lines of the script are:

import sys
print sys.path

import string
import os
import arcgisscripting

The value that is being printed for sys.path is:

>>> ['C:\\ARCGIS~1\\GEOPRO~1\\TGT_GP~1\\Scripts', 'C:\\ARCGIS~1\\GEOPRO~1\\TGT_GP~1\\Scripts', 'c:\\program files (x86)\\arcgis\\desktop10.1\\bin', 'c:\\program files (x86)\\arcgis\\desktop10.1\\ArcPy', 'c:\\program files (x86)\\arcgis\\desktop10.1\\ArcToolbox\\Scripts', 'C:\\arcgisserver\\geoprocessing\\TGT_GPExporter\\ExportGeoPDF.tbx', 'C:\\Windows\\system32\\python27.zip', 'C:\\Python27\\ARCGIS~1.1\\DLLs', 'C:\\Python27\\ARCGIS~1.1\\lib', 'C:\\Python27\\ARCGIS~1.1\\lib\\plat-win', 'C:\\Python27\\ARCGIS~1.1\\lib\\lib-tk', 'C:\\Python27\\ARCGIS~1.1\\Lib\\SITE-P~1\\PYTHON~1', 'C:\\Python27\\ARCGIS~1.1', 'C:\\Python27\\ARCGIS~1.1\\lib\\site-packages', 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.1\\bin64', 'C:\\Python27\\ARCGIS~1.1\\lib\\site-packages\\win32', 'C:\\Python27\\ARCGIS~1.1\\lib\\site-packages\\win32\\lib', 'C:\\Python27\\ARCGIS~1.1\\lib\\site-packages\\Pythonwin', 'C:\\Program Files\\ArcGIS\\Server\\bin', 'C:\\Program Files\\ArcGIS\\Server\\arcpy', 'C:\\Program Files\\ArcGIS\\Server\\ArcToolbox\\Scripts']

The script fails when it attempts to import arcgisscripting.

I don't understand where all the references to 'c:\\program files (x86)\\arcgis\\desktop10.1\\bin', etc., are coming from.
0 Kudos
AlanStewart
Frequent Contributor
I fixed my immediate issue by installing the 32-bit version of PythonWin and setting the GeoProcessing Options to use that version.
0 Kudos
DanielAmrine
Frequent Contributor

I have been trying to run this script which was converted from old VBA...

Attempted in PythonWin
PythonWin 2.7 (r27:82525, Jul 4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on win32.

When i add import arcpy to the beginning I get the following traceback:
Traceback (most recent call last):
File "C:\Python27\Lib\SITE-P~1\PYTHON~1\pywin\framework\scriptutils.py", line 325, in RunScript
exec codeObject in __main__.__dict__
File "C:\Python27\HCA_TO~1\polytorec_231may13.py", line 4, in <module>
import arcpy
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcPy\arcpy\__init__.py", line 17, in <module>
from geoprocessing import gp
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcPy\arcpy\geoprocessing\__init__.py", line 14, in <module>
from _base import *
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcPy\arcpy\geoprocessing\_base.py", line 14, in <module>
import arcgisscripting
ImportError: DLL load failed: %1 is not a valid Win32 application.
The process this code contains is a tool we really need and I have been "Beating" my head against the python wall trying to get this to run...so any help is much appreaciated.
0 Kudos
curtvprice
MVP Esteemed Contributor
Your path is set up to import the wrong Python (notice you are running 64 bit python and the arcpy path that fails is the 32 bit ArcGIS python). The easiest solution is to set up pythonwin to start up the 32-bit python shipped with ArcGIS, in your case: C:\python27\arcgis10.1\python.exe

If you must have 64 bit Python (including, say the x64 background geoprocessing), you should have python launch from C:\python27\arcgis10.1x64\python.exe

Unless you have a specific special need for 64 bit, I recommend using the 32 bit arcpy, as the 64 bit has some limitations and of course is not the same one you access from the ArcMap python command line.

UPDATE: On more reflection, I think you can fix this issue easily by uninstalling PythonWin and then downloading and installing the 32-bit PythonWin instead of the 64-bit version. Just that one change should solve the problem for you.
0 Kudos
DanielAmrine
Frequent Contributor
Your path is set up to import the wrong Python (notice you are running 64 bit python and the arcpy path that fails is the 32 bit ArcGIS python). The easiest solution is to set up pythonwin to start up the 32-bit python shipped with ArcGIS, in your case: C:\python27\arcgis10.1\python.exe 

If you must have 64 bit Python (including, say the x64 background geoprocessing), you should have python launch from C:\python27\arcgis10.1x64\python.exe 

Unless you have a specific special need for 64 bit, I recommend using the 32 bit arcpy, as the 64 bit has some limitations and of course is not the same one you access from the ArcMap python command line. 

UPDATE: On more reflection, I think you can fix this issue easily by uninstalling PythonWin and then downloading and installing the 32-bit PythonWin instead of the 64-bit version. Just that one change should solve the problem for you.


I did what you said and it didn't run the script but gave me this traceback:

Traceback (most recent call last):
File "C:\Python27\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript
exec codeObject in __main__.__dict__
File "C:\Users\damrine\Desktop\HCA_TOOLS\polytorec_231may13.py", line 4, in <module>
import arcpy

File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 17, in <module>
from geoprocessing import gp
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\__init__.py", line 14, in <module>
from _base import *
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 14, in <module>
import arcgisscripting
ImportError: Module use of python26.dll conflicts with this version of Python.

I've looked for the python27.dll in the C:/python27 but i can't find it and I can't find it in C:/program filex86/arcgis/desktop10.0/etc... either. I would think taking out the python26.dll in ArcMAP and replacing it with the python27.dll would fix it. Buti CAN'T find it!
0 Kudos