Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyinstaller in combination with ESRI's arcpy #576

Closed
pyinstaller-tickets-migration opened this issue Oct 18, 2014 · 7 comments
Closed

pyinstaller in combination with ESRI's arcpy #576

pyinstaller-tickets-migration opened this issue Oct 18, 2014 · 7 comments
Assignees

Comments

@pyinstaller-tickets-migration

Original date: 2012/07/17
Original reporter: herberga AND noord DASH holland DOT nl

I run into problems with pyinstaller and arcpy. I think the licensing mechanism in arcpy causes the problems.

Are you aware of this issue and is there a solution to this problem?
I want to ditribute the application using pyQt en arcpy. The user's who use it have a valid arcview license for ArcGIS.

@htgoebel
Copy link
Member

Original date: 2012/07/17

There is no knwon issue with arcpy. I do not even know arcpy.

To give you a more complete answer, please give more detailed information about arcpy and the problem.

If it's some "licensing mechanism in arcpy", I suppose to ask ESR. PyInstaller does not implement any license management.

@htgoebel
Copy link
Member

Original date: 2014/04/21

I'm closing this ticket since there has been no feedback for 21 months now.

@pyinstaller-tickets-migration
Copy link
Author

Original date: 2014/06/09
Original reporter: *jamessramm AND gmail DOT COOM *

arcpy is a licensed library from ESRI that is actually bindings to a C++ library.

Arcpy is not actually installed in the python path, and in order for it to work, an installation of ArcGIS installs it's own version of python with a '.pth' file pointing to the arcpy folder within the ArcGIS installation folder.

You can make ArcPy work with another python installation by including a .pth file in the python directory (usually something like C:\Python27) which points to the arcpy installation (in something like C:\ProgramFiles\ArcGIS).

So, a workaround to get pyinstaller to work with ArcPy is to exclude the arcpy module from the build (using the excludes statement in the spec file) and include the .pth file in the distribution folder (or perhaps in the executable?).

I haven't tested this, but it should make the python environment setup by the bootloader include the arcpy directory in it's path, so arcpy can be imported.

Of course, this relies on the client machine having ArcGIS installed in the standard location.

Basically, you are looking for a way to make an executable made with pyinstaller include modules which are not in the installation folder.

@blah238
Copy link

blah238 commented Nov 18, 2016

I just wanted to update this issue with some additional information.

I came across @JamesRamm's archook which helps with locating arcpy's directories and putting them on sys.path. I used this in a runtime hook to get most of the way there.

There were still a couple of issues such as needing to add a hidden glob import, add a fake site-modules directory to sys.path, and put a fake numpy module in sys.modules (could have added it as a hidden import as well but why bloat the filesize for something that won't be used?).

Here's the runtime hook code:

# ./hooks/rthooks/pyi_rth_arcpy.py
import sys

# Add arcpy's directories to sys.path
from archook import get_arcpy
get_arcpy()

# Additional tweaks to placate arcpy
from types import ModuleType
sys.path.append('./site-packages')  # Add a dummy site-packages folder to sys.path
sys.modules['numpy'] = ModuleType('numpy')  # Add a fake numpy module to sys.modules

And here's the relevant part of my .spec file:

# ...
    hiddenimports=['glob'],
    runtime_hooks=['./hooks/rthooks/pyi_rth_arcpy.py'],
    excludes=['arcpy'],
# ...

Interested to see if anyone else has come up with another/better solution to using arcpy with a frozen executable. An official hook would be welcomed BTW!

One question I have is how to both exclude arcpy and have a build-time hook run for it? If I add it to my excludes, my build-time arcpy hook is skipped. If I don't exclude it in the spec file, but put it in the excludedmodules property of the build-time hook, it is not excluded. Catch-22?

Using 3.3.dev0+483c819.

@channabasavagola-zz
Copy link

Thanks, @blah238 and @JamesRamm for the workaround. It helped me bundle my python script with Arcpy functionalities into a .exe. I'm now able to run the exe on the same computer with ArcGIS installed, but I wanted to run it on a computer where ArcGIS is not installed (Basically Linux using Wine emulator). Can you help me?

@alanscandrett
Copy link

Thanks, @blah238 and @JamesRamm for the workaround. It helped me bundle my python script with Arcpy functionalities into a .exe. I'm now able to run the exe on the same computer with ArcGIS installed, but I wanted to run it on a computer where ArcGIS is not installed (Basically Linux using Wine emulator). Can you help me?

That would entail copying the ArcPy libs in whole or partially, in either case that breaks the ArcPy EULA and is not advisable.

@JamesRamm
Copy link

Hi @channabasavagola
Running a script that uses ArcPy on a computer where arcGIS is not installed will most certainly not work as they include license checks when you import arcpy

I believe you can install the 'ArcGIS API For Python' on any system (https://developers.arcgis.com/python/), but its functionality, specifically the 'arcpy' functionality will be limited without required licenses.

Unless you have a specific need for reading ArcGIS proprietary data files then my recommendations on linux (or any OS for that matter) is always to use the open source OSGeo software. This includes QGis, but for developing your own scripts/software, GDAL alone will often provide all you need

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants