Trouble with py2exe and arcpy / arcgisscripting

4989
7
Jump to solution
03-21-2013 02:33 PM
deleted-user-Me5W-uJw0Ojh
New Contributor II
I'm trying to build an exe using py2exe.  My script uses wxPython for a GUI, and arcpy for an Insert Cursor and an Update Cursor on one table inside of a personal gdb.  I'm using ArcGIS 10.0 and Python 2.6, and Aptana Studio 3 + pyDev as an IDE.

The script works great inside Aptana.  My setup.py script executes and creates an EXE file inside of the dist folder of my project directory.  When I try to run the EXE, it crashes on import of arcpy.  The log file shows the following error:

Traceback (most recent call last):   File "redrover-hazus.py", line 66, in <module>   File "zipextimporter.pyo", line 82, in load_module   File "arcpy\__init__.pyo", line 17, in <module>   File "zipextimporter.pyo", line 82, in load_module   File "arcpy\geoprocessing\__init__.pyo", line 14, in <module>   File "zipextimporter.pyo", line 82, in load_module   File "arcpy\geoprocessing\_base.pyo", line 14, in <module>   File "zipextimporter.pyo", line 98, in load_module ImportError: MemoryLoadLibrary failed loading arcgisscripting.pyd


My setup.py script looks like this:

from distutils.core import setup import py2exe, sys, os  data_files = ["file1", "file2"]   sys.argv.append('py2exe')  setup(     windows = [{'script': "script.py",'icon_resources':[(1,"icon.ico")]}],     zipfile = None,     data_files=data_files,     options = {'py2exe':                  {                  'includes': "arcgisscripting",                  'bundle_files': 1,                  'dist_dir': "dist",                  'optimize': 2,                 }               }, )


All of the users who will run this EXE will already have ArcGIS 10.0 and Python 2.6.  Is there a way I can specify this in my setup.py file?

-- Josh Groeneveld
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
deleted-user-Me5W-uJw0Ojh
New Contributor II
I found a solution to do what I needed to do.  The set of scripts I wanted to bundle together only used the arcpy module for one search cursor and one insert cursor.  I re-wrote my scripts to use the pyodbc module rather than arcpy, since the file the scripts work with is an Microsoft Access file (.mdb).  Since my scripts no longer call arcpy, py2exe generated a perfectly functioning EXE.  Thanks Matt and Curt for your advice.  It was very helpful to me.

View solution in original post

0 Kudos
7 Replies
curtvprice
MVP Esteemed Contributor
I'm trying to build an exe using py2exe.

See this thread

Re: ArcGIS 10.1 python script to exe is not working​  (updated link)

I suppose the main question is - why are you using py2exe? If someone has ArcGIS installed, they will have Python installed as well. If you are trying to hide your code you can b-code compile it (pyc).

0 Kudos
deleted-user-Me5W-uJw0Ojh
New Contributor II
If I byte-compile my code, will it give the user any other Python modules I have that they might not (such as wxPython)?  While I understand that anyone who has ArcGIS already has Python, there are other Python modules (aside from arcpy), that the users need for the script to work.  Also, my script ties into three other scripts that also need to be distributed along with the main script.

My intention for creating an EXE is to bundle everything needed into one place.
0 Kudos
MathewCoyle
Frequent Contributor
You cannot compile a python script importing arcpy into an exe.
0 Kudos
yingjieliu
New Contributor

Why we cannot compile a python script importing arcpy into an exe, by the way, I tried to convert .py into .exe with arcpy ,but there are some problems, so I want to know the reason

problem.bmp

0 Kudos
deleted-user-Me5W-uJw0Ojh
New Contributor II
You cannot compile a python script importing arcpy into an exe.

How come?

If this is not possible, are there other options that would help me distribute the set of scripts and non-arcpy modules that the user needs to run it?
0 Kudos
curtvprice
MVP Esteemed Contributor
If this is not possible, are there other options that would help me distribute the set of scripts and non-arcpy modules that the user needs to run it?


See the python documentation on distutils:

Distributing Python Modules
0 Kudos
deleted-user-Me5W-uJw0Ojh
New Contributor II
I found a solution to do what I needed to do.  The set of scripts I wanted to bundle together only used the arcpy module for one search cursor and one insert cursor.  I re-wrote my scripts to use the pyodbc module rather than arcpy, since the file the scripts work with is an Microsoft Access file (.mdb).  Since my scripts no longer call arcpy, py2exe generated a perfectly functioning EXE.  Thanks Matt and Curt for your advice.  It was very helpful to me.
0 Kudos