Frozen exe crashes when importing arcpy

1287
7
12-07-2016 10:36 AM
WayneBoras
New Contributor III

Hello,

 

I have created a Python application that I would like to distribute within our organization. I have created a frozen exe using cx_Freeze, but the exe crashes in GeoprocessingLib.dll. I have isolated the problem to a very simple example. Here is the Python code:

 

test.py:

import arcpy
print('Hello world!')

And here is the command to create the frozen exe:

cxfreeze test.py

 

Here are the error details from Windows Event Viewer:

Faulting application name: test.exe, version: 0.0.0.0, time stamp: 0x0001e4e4

Faulting module name: GeoprocessingLib.dll, version: 10.1.1.3300, time stamp: 0x52e02880

Exception code: 0xc0000005

Fault offset: 0x00154eda

Faulting process id: 0x1804

Faulting application start time: 0x01d250b28e4a7d73

Faulting application path: Z:\lethpy-trees\lethpy\gistools\dist\test.exe

Faulting module path: C:\Users\11157\AppData\Local\Temp\_MEI50322\GeoprocessingLib.dll

Report Id: cdb968dd-bca5-11e6-82d8-3417ebaaaccc

Faulting package full name:

Faulting package-relative application ID:

 

I have tried both cx_Freeze and pyInstaller to create the standalone exe, but the problem is the same. We are using ArcGIS 10.1 SP1.

 

Any help would be appreciated.

0 Kudos
7 Replies
ClintonDow1
Occasional Contributor II

Unfortunately I don't think this will work like you're expecting. ArcPy relies on a large portion of the underlying ArcGIS application to execute the breadth of its functionality. If you're attempting to package a script that imports arcpy it would have to include the majority of ArcGIS within that package to be functional. Even in that case I'm not sure it would work since ArcGIS also relies on registry keys etc which are set during it's install. 

I would suggest looking into creating a Python Package instead of creating an executable - How To Package Your Python Code — Python Packaging Tutorial  - this is a widely used method of sharing arcpy scripts. 

0 Kudos
WayneBoras
New Contributor III

Thanks Clinton. For simplicity, I was hoping to avoid distributing the app as a Python Package and just create a single-file executable that I could make available on a network share. This method would allow people within the organization to run the app without having to worry about a proper Python environment, installing libraries, etc.

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

Have you looked at creating a python addin.  They would still have to have ArcGIS installed, but you can include all your scripts, toolbars, buttons, user-interface, additional libraries, etc in a single .addin file. The double-click and it installs where needed.

http://www.arcgis.com/home/item.html?id=5f3aefe77f6b4f61ad3e4c62f30bff3b#! 

WayneBoras
New Contributor III

Hi Rebecca,

I have not tried that, but I will take a look. Thanks for the information!

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

To help you get started, here is a doc I put together a while back Tip: Python Addin - getting custom tools/toolbox to work - GPToolDialog    I

Also check out E360 Video Search | Esri Videos   (filtered for "python addin") and I found some videos about python addins on you tube last night (happens to be a class from Univ of Alaska - Fairbanks) that I think could be helpful. 

My suggestion, use the wizard to set up the structure...add a few "spare" buttons (i.e. have it stub out the button) if wanting to use a toolbar and buttons.  Easier to do that at the start and delete if not needed (my opinion), since the names will automatically be unique (versus copy-past a new one).

Make sure you get your script working, and working in the toolbox (i.e. add script, have it give the user GUI for parameters, etc).  If it doesn't work there, putting into an addin isn't going to make it better. But you can always tweak, add, or whatever and refresh the .addin (and load back into your Catalog OR Map).

Word of caution...the toolbar/tools will work in Pro (if you update for the new Python software see /blogs/dan_patterson/2016/05/09/the-links  for links to what you will need for Pro) but Addins themselves are not supported.  I'm hoping this will change, but the issue is with the ribbon style menus of Pro and trying to modify/customize those...at least that is what I've been told.  Hopefully they will accommodate this in the future...hope hope)

0 Kudos
WayneBoras
New Contributor III

Thanks again, Rebecca. The application that I created requires a few third-party Python libraries including wxPython, which  has to be installed separately. Also, the app will only be used on a handful of workstations, and I wanted users to be able to run it without having to start ArcMap first. For these reasons, I decided to go with manual installation and run the app using a batch file.

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

I include special libraries in my Addin structure  for my addins, so I make sure all are seeing the same (psutil in clip below).   also include special "sde" or other connection files in my "conn" folder...just make sure not to include passwords in the connection file. 

Anyway, sounds like you are on you way.  Have fun!

0 Kudos