Select to view content in your preferred language

ArcGIS 10.1 python script to exe is not working

8400
9
08-15-2012 11:12 AM
SteveXu
Regular Contributor
I updated my python script from ArcGIS 9.3 Python 2.5 to ArcGIS 10.1 Python 2.7. The script is working from python 2.7 GUI, however, when I converted to exe by py2exe, and then ran the exe, I got the following errors:

C:\Python27\ArcGIS10.1\dist>SDEGetLatLongOfAProjectedPoint.exe
Traceback (most recent call last):
  File "SDEGetLatLongOfAProjectedPoint.py", line 1, in <module>
  File "arcpy\__init__.pyc", line 21, in <module>
  File "arcpy\geoprocessing\__init__.pyc", line 14, in <module>
  File "arcpy\geoprocessing\_base.pyc", line 14, in <module>
  File "arcgisscripting.pyc", line 12, in <module>
  File "arcgisscripting.pyc", line 10, in __load
ImportError: DLL load failed: The specified procedure could not be found.

I have 2 PCs, one pc is for ArcGIS 9.3.1 with python 2.5. the other for ArcGIS 10.1 with Python 2.7.

By the way, my python 2.5 script converted to the exe, which is working.

My Python 2.7 and py2exe for Python 2.7 is working. I created a generic python script (without using any import arcpy libraries), and converted it to the exe, which is working.

Please help. Thanks
Tags (2)
0 Kudos
9 Replies
JasonScheirer
Esri Alum
It's kind of amazing that a py2exe script that used arcgisscripting/arcpy ever worked this way at all. What looks like is happening is the DLL is loading the wrong version (python 2.7 loading a python 2.6 PYD, or a 10.0 arcgisscripting.pyd trying to load 10.1 DLLs into the process), or much more likely, py2exe isn't bringing over everything it needs. I'd assume it to be difficult to the point of it not being worth it to include the full binary distribution of the subset of arcobjects needed to do what you need, or some hack with __import__ and the registry to find and add the ArcGIS installation directory to Python's path to load the installed arcgisscripting without triggering py2exe's import consolidation mechanics which is creating this strange condition. You'll need to exclude arcgisscripting in your build script.

Why exactly are you converting a script to executable? To obscure the source? That can be done more easily by embedding the script in your toolbox and password protecting it, or distributing bytecode (.pyc) files you call indirectly from your script.
0 Kudos
SteveXu
Regular Contributor
Jason:

I completely agree with you. My ArcGIS 10.1 python 2.7 XP PC is not a clean pc. I removed the old ArcGIS9.3/10.0, however, which didn't clean everything. So I will use a clean PC with a fresh ArcGIS 10.1 to do the test.

I just used to use py2exe to create the exe for our internal users. Most of them are running as windows' scheduled tasks. However, I'm open to any suggestions.

Thank you very much for your insights on this issue.
0 Kudos
SteveXu
Regular Contributor
Hi Jason:

I just came cross this website http://popdevelop.com/2010/04/how-to-build-an-executable-application-from-your-python-script-qt-spec...

Based on Mike's post on the website, Looks like I need to add some ArcGIS dlls in my setup.py. DO you have any insights on this?

However, when I am using ArcGIS 9.3.1 with Python 2.5 and py2exe, I don't need to exclude/include any ArcGIS dlls. I only need to exclude 'MSVCP90.dll' in the setup.py.

Thanks
0 Kudos
JasonScheirer
Esri Alum
Yeah, I'm not entirely sure what is going on. You might want to compare the logs and manifests of either when they create the executable and bundle it all together. Hopefully the list of files included is roughly the same but one or two obvious additions or omissions that are the culprits.

A lot has changed under the hood in the architecture in ArcGIS since 9.3.1, hence my surprise that it ever worked at all.
0 Kudos
hcbai
by
New Contributor
Traceback (most recent call last):
  File "splitMain.py", line 11, in <module>
  File "splitUI.pyc", line 11, in <module>
  File "test2.pyc", line 18, in <module>
  File "arcpy\__init__.pyc", line 21, in <module>
  File "arcpy\geoprocessing\__init__.pyc", line 14, in <module>
  File "arcpy\geoprocessing\_base.pyc", line 14, in <module>
  File "arcgisscripting.pyc", line 12, in <module>
  File "arcgisscripting.pyc", line 10, in __load
ImportError: DLL load failed: �?�不�?��??�?�??模�?�??

Hey, how did you solve the problem?Can you please share?
0 Kudos
StacyRendall1
Frequent Contributor
One workaround for this, so that you can still distribute an exe file, is to make a wrapper script which gets converted to exe and distribute it with a pyc file that actually does the calculation. For example (very simple, not really recommended, but will work - see below for a better option):

Code script: doSomething.py
import arcpy
# do some stuff
# do some more stuff


Wrapper script: wrapper.py
import doSomething


You simply have to run wrapper.py, it will import doSomething.py and make a *.pyc file from it. Then you can use py2exe on wrapper.py. Then you simply have to keep the doSomething.pyc file with the exe when you distribute it.

RECOMMENDED IMPLEMENTATION

Code script: doSomething.py
import arcpy
def main():
    # do some stuff
    # do some more stuff

if __name__ == '__main__':
    pass # will do nothing if someone tries to run it directly


Wrapper script: wrapper.py
import doSomething

doSomething.main()
0 Kudos
TrilliumLevine1
Deactivated User

Stacy's workaround isn't working for me either (with 10.2.2), I'm getting the error message shown in the screenshot when trying to run the exe in the command line.  I'm also getting a message in the command line re: missing modules (see screenshot), but am not sure where I can find these...any ideas???

0 Kudos
yingjieliu
Deactivated User

I had the Similar problem when I using ArcGIS 10.3  arcpy with Python 2.7 and cxfreeze to convert .py into exe

problem.bmp

can you give me some suggest to solve the problem?

thanks!

LaurenPeckman
Occasional Contributor

I have the exact same problem as liuyingjie above, not finding a clear solution. 

0 Kudos