0

I'm a beginner in Python. I don't believe this is a duplicate question, because the other questions seem to be concerned with starting a conda environment within a command line. I want it to happen on double-click.

I'm writing a script that pulls earthquake information from the USGS's API, plots the coordinates as a point, and appends the data to a pre-existing feature class. It works as a .py on my own machine, both on double-click and when running from the terminal or the python shell. However, the .py version of the script doesn't work on certain computers in our office, presumably because it's using some extra packages that I've got installed or something.

I need it to be able to run easily on double-click on any of our computers without any configuration nonsense on the user's end. To accomplish this, I compiled the script and all of its packages into an .exe with auto-py-to-exe. I already tried both py2exe and pure pyinstaller, and this appears to be the most straightforward converter for my purposes. All of the simple scripts that I have tested with it work perfectly. But when I try to convert my spatial program, I get this error message in the terminal -- presumably because of ArcPy's inclusion:

arcpy must be run from inside the Conda environment, which ArcGIS uses to manage the installation of Python.
You can access this environment by launching Python from the links inside the "ArcGIS > ArcGIS Pro" Start Menu Group:
"Python Interactive Terminal" starts a Python session.
"Python Command Prompt" opens a Command Prompt window initialized with Conda.

Or by running the proenv.bat file in the terminal
C:\> C:\Program Files\ArcGIS\Pro\bin\python\scripts\proenv.bat

Traceback (most recent call last):
File "UpdateEarthquakesDB_final.py", line 5, in <module>
File "PyInstaller\loadr\pyimod03_importers.py", line 540, in exec_module
File "arcpy\__init__.py", line 70, in <module>
ImportError: arcpy needs to run within an active ArcGIS Conda environment
[22316]

Should my goal be to somehow bundle a conda environment with an .exe, to be automatically activated on double-click, or should I go about this some other way?

1
  • 1
    You've got a potential licensing issue here, since installing ArcPy doesn't grant an ArcGIS license seat.
    – Vince
    Jun 24 at 1:17
2

To return to this question, I ended up giving up and configuring the users' computers myself so the script could run on double-click as a .py. As Vince said, it's a stubborn licensing issue with arcpy.

For passersby who may be interested in accomplishing what I could not, this may be a helpful resource: https://community.esri.com/t5/python-questions/using-py2exe-with-arcpy-it-can-be-done-easily/td-p/360520

I couldn't get it to work, but perhaps you can. I only have access to Pro, but the comments on this post imply this will only work with ArcMap.

0

Pyinstaller should be able to do this for you as long it was installed in the same environment as the dependencies (modules/libraries) for your script. Pyinstaller finds all import statements in your script and can compile everything into a single .exe file.

https://pyinstaller.readthedocs.io/en/stable/operating-mode.html

1
  • 1
    Except Pyinstaller isn't going to deal with Esri licensing.
    – Vince
    Jun 24 at 1:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.