I have a 2008R2 server with both ArcGIS Desktop 10.1 (with Background Geoprocessing) and ArcServer 10.1 installed. I've developed a custom Python package that I deploy to C:\Python27\ArcGISx6410.1\Lib\site-packages. I also created a PYTHONPATH environment variable pointing to this same directory. Finally, I added C:\Python27\ArcGISx6410.1 to my PATH environment variable.
Previous to yesterday I could test my Python package within ArcMap, which is consumed through a Python Toolbox. For reasons unknown to me, I started getting exceptions. I boiled the problem all the way down to not even being able to 'import arcpy' within ArcMap's Python interpreter. I was getting the exception:
>>> import arcpy Runtime error Traceback (most recent call last): File "<string>", line 1, in <module> ... File "D:\Python27\ArcGISx6410.1\Lib\site-packages\numpy\core\__init__.py", line 5, in <module> import multiarray ImportError: DLL load failed: %1 is not a valid Win32 application.
That's pretty serious when you can't even import arcpy within ArcMap. Long story short, I ended up having to remove the PYTHONPATH environment variable to import arcpy successfully. However, when I tried to run my custom tools within ArcMap exceptions were still being thrown. On a whim I copied my Python package into the 32-bit site-packages directory (C:\Python27\ArcGISx6410.1\Lib\site-packages), which got everything running again.
While I did find solutions to the issues, I'm unclear about what caused the problem in the first place? Furthermore, I'm very unclear on why I had to deploy my package for 32-bit, as ArcMap should be using 64 bit (I have background GP turned on).
Would life be easier if I deployed my Python package somewhere other than C:\Python27\ArcGISxxx and then set the PYTHONPATH to that directory? Any best practices?
I ended up moving my Python package out of C:\Python27\ArcGISx6410.1\Lib\site-packages and into D:\geoprocessing, then set my PYTHONPATH to search the new location. Still not sure what sparked the problem though.
I ended up moving my Python package out of C:\Python27\ArcGISx6410.1\Lib\site-packages and into D:\geoprocessing, then set my PYTHONPATH to search the new location. Still not sure what sparked the problem though.