Esri / arcgis-python-api

Documentation and samples for ArcGIS API for Python
https://developers.arcgis.com/python/
Apache License 2.0
1.9k stars 1.1k forks source link

Error when package arcgis script with pyInstaller #1416

Closed sinki-blau closed 1 year ago

sinki-blau commented 1 year ago

Describe the bug script is beinging packaged by PyInstaller. If 'arcgis' library is imported, package is built successfully yet when launching dist .exe, many errors occur because of the .arcgis/auth library.

To Reproduce Steps to reproduce the behavior:

pyinstaller -w --onefile test_package_gis.py
import numpy as np
import PySimpleGUI as sg
import arcgis 
from arcgis.gis import GIS

def main():
    print('Hello world')
    print(np.arange(1, 5))

    PortalUserName = x #any arcgis online username
    PortalPassword = x #password
    PortalUrl = x #organization portal
    survey_item_id = # survey item id
#
    print('Get GIS layer')
    gis = GIS(PortalUrl, PortalUserName, PortalPassword)
    survey_by_id = gis.content.get(survey_item_id)
    featureLayer = survey_by_id.layers[0]
    features = featureLayer.query(where='1=1').features

    print(len(features))
    sg.theme('DarkAmber')   # Add a touch of color

    # All the stuff inside your window.
    layout = [[sg.Text('Hello World GIS', len(features))],
              [sg.Text('This is a test'), sg.InputText()],
              [sg.Button('Ok'), sg.Button('Cancel')]]

    # Create the Window
    window = sg.Window('Window Title', layout)
    # Event Loop to process "events" and get the "values" of the inputs
    while True:
        event, values = window.read()
        if event == sg.WIN_CLOSED or event == 'Cancel':  # if user closes window or clicks cancel
            break
        print('You entered ', values[0])

    window.close()

if __name__ == "__main__":
    main()

error: MicrosoftTeams-image (2)

Screenshots If applicable, add screenshots to help explain your problem.

Expected behavior Unsure why when importing arcgis library, even if script is being packaged, the .exe file still couldnt' run.

Platform (please complete the following information):

achapkowski commented 1 year ago

We have never used pyinstaller. Can you provide some further details on this? Does it fail from a pure script?

sinki-blau commented 1 year ago

We have never used pyinstaller. Can you provide some further details on this? Does it fail from a pure script?

Hi! thanks for the reply! This pyInstaller is to package code into an executable .exe file. The purpose of importing arcgis package (ArcGIS API for Python) is that we want to download photos from survey123, a feature service. And the users can just use it out of the .exe package. But our problem is that even if its a simple import of arcgis with pyinstaller, it gives error and doesn't work.

You can see pyinstaller here https://realpython.com/pyinstaller-python/

Really appreciate your help!

Thanks, Braundt

achapkowski commented 1 year ago

Ok thanks for explaining that, my question is does your logic work without using pyinstaller?

This will help us try and see if it's pyinstaller or our package.

BharatShukla30 commented 1 year ago

Facing a similar issue when trying to create a dist using pyinstaller of the script where arcgis is imported, getting the same error message as well. @achapkowski

nanaeaubry commented 1 year ago

We do not use pyinstaller but the error might be a python version mismatch. As of 2.1.0.3 the supported versions of Python are 3.7-3.9.

nanaeaubry commented 1 year ago

At the next version (2.2.0) we will drop support for python 3.7 and 3.8 and have support for python 3.9, 3.10, 3.11