Cannot run my compiled Python exe file?

12811
4
12-30-2015 02:20 PM
SteveXu2
New Contributor

I have created a python script (Parcel_Account_2.py), which
is working.

Now, I used py2exe to create an exe file (Parcel_Account_2.exe), which is not working. The following screenshot is the
error:

  tracebackErr.png

I’m using ArcGIS 10.2 with python 2.7.3(Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32). I think
the traceback information seems showing some arcpy files cannot be found. Unfortunately, I cannot fix the problem. Would you please help?

Originally, I sent this request to ESRI support, and told "Unfortunately, py2exe is not an Esri product and
is not supported by Esri.
".  I still wonder Why  the compiled exe couldn't only find those ESRI arcpy files? My python script also imports a third-party dll (cx_Oracle) which has been successfully pakaged into dist folder. Those arcpy files shown on the above screenshot can be found under C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy. I successfully compiled my Parcel_Account_2.py by py2exe, but when I ran Parcel_Account_2.exe, and got the traceback importError in the screenshot. How to resolved the issue? Thanks a lot.

Message was edited by: Steve Xu I just did a test, which may give more information. My test is as follows: I created a simple python script named as HelloWorld.py with one line below: print "Hello World!" Then created a setup.py as follows: from distutils.core import setup import py2exe setup(console=['HelloWorld.py']) Then ran the following command: python setup.py py2exe Then ran HelloWorld.exe No problem. I got the correct output as Hello World! However, when I added import arcpy into my HelloWorld.py, re-ran all commands, I got the exact same traceback and ImportError message. How can I make the arcpy working by compiling my python script (Parcel_Account_2.py) using py2exe?

0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus

Probably because of the need for end users to have an installation of arcgis on their computer.  The paths and functons needed to successfully run a python script are not fully exposed unless one calls arcpy from within a python environment.  The necessary components were not used during the compilation process and you will be wasting your time trying to find all the necessary components.

In short...skip trying to create an exe, create one of the incarnations of a python tool for use within arcmap or used as a service.

0 Kudos
SteveXu2
New Contributor

Dan,Thank you for your comments and suggestions.

I'm creating python scripts which will be scheduled to run on the server. I did the same from ArcGIS 9.3 without issues. I'm still thinking the same approach should be working at ArcGIS 10.2.

0 Kudos
DanPatterson_Retired
MVP Emeritus

well the dll error suggests that you have used something that isn't 32-bit perhaps

0 Kudos
SteveXu2
New Contributor

Dan:

That's also my first thought.

However, my test showed that the issue is somehow related to arcpy? After run the command 'python setup.py py2exe', running the created exe cannot find those arcpy related files. My python script is working as follows:

1, running it in IDLE (python GUI)

2. running it in Pythonwin

3. running it in a bat file as C:\Python27\ArcGIS10.2\python.exe C:\.....\Parcel_Account_2.py

Why it is not working after being compiled? or why it cannot find those dlls (arcpy files) after being compiled?

Thank you very much.

0 Kudos