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

Workbench crash reported on Windows #1559

Open
emlys opened this issue Apr 18, 2024 · 6 comments
Open

Workbench crash reported on Windows #1559

emlys opened this issue Apr 18, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@emlys
Copy link
Member

emlys commented Apr 18, 2024

A user reported

I’ve just installed InVEST on windows and tried opening i. The logo shows on the screen for several seconds but then disappears and nothing else happens.

Their main.log file is attached:
main.log

The server fails to start up because of an error loading GDAL:

Traceback (most recent call last):
  File "osgeo\__init__.py", line 30, in swig_import_helper

[16:21:54.457] [C:\Users\Mark Brown\AppData\Local\Programs\InVEST 3.14.1 Workbench\resources\app.asar\build\main\main.js]   File "importlib\__init__.py", line 126, in import_module
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 676, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 573, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1233, in create_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
ImportError: DLL load failed while importing _gdal: The specified procedure could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "invest\cli.py", line 16, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "natcap\invest\datastack.py", line 35, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "osgeo\__init__.py", line 46, in <module>
  File "osgeo\__init__.py", line 42, in swig_import_helper
ImportError: Traceback (most recent call last):
  File "osgeo\__init__.py", line 30, in swig_import_helper
  File "importlib\__init__.py", line 126, in import_module
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 676, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 573, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1233, in create_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
ImportError: DLL load failed while importing _gdal: The specified procedure could not be found.

On Windows, with Python >= 3.8, DLLs are no longer imported from the PATH.
If gdalXXX.dll is in the PATH, then set the USE_PATH_FOR_GDAL_PYTHON=YES environment variable
to feed the PATH into os.add_dll_directory().
[32240] Failed to execute script 'cli' due to unhandled exception!
@emlys emlys added the bug Something isn't working label Apr 18, 2024
@asoluer
Copy link

asoluer commented Apr 28, 2024

The same error occurred after I downloaded and installed the software.

@asoluer
Copy link

asoluer commented May 3, 2024

I am now ready to answer this question, as I roughly understand what the issue is (from my perspective):
First, there appears to be a misconfiguration in your system variables, possibly due to installing third-party package managers like Anaconda, which might have caused path conflicts, preventing GDAL from functioning properly. You can refer to my environment settings as illustrated in Image 1. Moreover, if you're using invest in Python (I chose Python 3.10 for my setup) and encounter a GDAL error—even though it's installed via Conda and exists in the virtual environment :)—the command-line environment, such as Windows PowerShell, might be correct (as shown in Image 2). However, errors might still occur in an IDE like PyCharm (as depicted in Image 3). At this point, you'll need to manually specify the appropriate path in the environment (as shown in Image 4), which should then allow it to run smoothly in the IDE. (I have not conducted further experiments yet, so I can't guarantee there won't be additional errors,I hope it works for you).
image

image
8a982fd7b4d2c2f44f2ee58eeeb32892

image

@asoluer
Copy link

asoluer commented May 3, 2024

image
Following the initial setup mentioned above, I have successfully resolved the software crash issue, and you should now be able to open the software interface normally. (It's important to note that modifying the system environment variable path should be done with caution, as it might cause other issues.)

@emlys
Copy link
Member Author

emlys commented May 3, 2024

@asoluer are you building and running the workbench yourself? Or are you running the workbench binary downloaded from here?

We use Pyinstaller to bundle all dependencies including GDAL into the binary executable, so it should be independent of your environment or IDE settings. It would be very strange if your IDE settings affected the InVEST binary. But if that is the case, please let us know! Thanks for investigating

@asoluer
Copy link

asoluer commented May 4, 2024

@emlys This indeed seems to be a peculiar issue. Initially, I downloaded the workbench version of the software directly from the website. After installing it, the software wouldn't open properly. I then attempted to run invest.exe via the command prompt, which led to the aforementioned error:

(Partial log found on a community forum, similar to my situation)

Traceback (most recent call last):
  File "invest\cli.py", line 16, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "natcap\invest\datastack.py", line 35, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "osgeo\__init__.py", line 46, in <module>
  File "osgeo\__init__.py", line 42, in swig_import_helper
ImportError: Traceback (most recent call last):
  File "osgeo\__init__.py", line 30, in swig_import_helper
  File "importlib\__init__.py", line 126, in import_module
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 676, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 573, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1233, in create_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
ImportError: DLL load failed while importing _gdal: The specified procedure could not be found.

On Windows, with Python >= 3.8, DLLs are no longer imported from the PATH.
If gdalXXX.dll is in the PATH, then set the USE_PATH_FOR_GDAL_PYTHON=YES environment variable
to feed the PATH into os.add_dll_directory().

I tried adding the USE_PATH_FOR_GDAL_PYTHON environment variable, but the error persisted (I'm unclear on the specific reasons and details).

Subsequently, I installed the software again on a colleague's computer and the problem disappeared. So, I checked my colleague's system environment variables, adjusted my settings accordingly, and removed the related anaconda paths, after which the software started working normally.

In an effort to understand the root cause, I tried building invest with conda after removing the anaconda path: conda install -c conda-forge natcap.invest. Oddly, this time there were no errors (previously the same command resulted in a gdal error), but the problem still occurred when using the compiler (as shown in the picture above, although it worked fine when run from the command line). So, I checked the location of gdal's dynamic link library and manually specified it in PyCharm, as: F:\anaconda\envs\invest\Library\bin. To my surprise, the problem was resolved.
I can only guess that it is related to the GDAL library, which suggests that I might be using GDAL incorrectly. However, I'm unclear as to why it would affect the Anaconda system environment variable PATH? (Even though the GDAL-related libraries were working fine before I removed the Anaconda PATH.)
I do not have a strong computer science background, so it's challenging to pinpoint where the issue lies. If you have any suggestions or guidance, please feel free to share! thx!

@emlys
Copy link
Member Author

emlys commented May 6, 2024

@asoluer would you mind trying with the latest development version and let us know if the same thing happens? You can download the "Workbench-Windows-binary" at the bottom of this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants