4

I figured that I would ask this question hoping that someone finds a document or provides a description that actually works. I've followed countless sites, GitHub issues, and other forum posts but have not been able to preserve command line functionality with Python scripts.

Using: Windows 10 and Python 3.7, 64 bit

I do not want to use OSGeo4W or their shell, or conda. I need to use the Windows binaries. I also need to use GDAL version 3.1 due to options not found in GDAL version 3.0

Here is what I have attempted so far. This installation is from scratch, without any dependencies installed.

  1. Navigate to the binaries (this version) and download the following: gdal-300-1911-x64-core.msi for the core (do typical install) and GDAL-3.1.0.win-amd64-py3.7.msi for the python bindings.
  2. Add C:\Program Files\GDAL to your PATH under system variables. Move it to the very top.
  3. Add these two system variables: GDAL_DRIVER_PATH=C:\Program Files\GDAL\gdalplugins and GDAL_DATA=C:\Program Files\GDAL\gdal-data
  4. Press OK and navigate to your command prompt.
  5. Type in gdalinfo --version. This should output GDAL 3.1.0dev, released 2019/99/99
  6. Type in gdal2tiles.py --xyz

At step 6, the application will break. Obviously, we need an input file, but that doesn't matter right now because we receive a different error. Here is what the command prompt outputs:

C:\Users\Bold>gdalinfo --version
GDAL 3.1.0dev, released 2019/99/99

C:\Users\Bold>gdal2tiles.py --xyz
Traceback (most recent call last):
  File "C:\Users\Bold\AppData\Local\Programs\Python\Python37\lib\site-packages\osgeo\__init__.py", line 18, in swig_import_helper
    return importlib.import_module(mname)
  File "C:\Users\Bold\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 670, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 583, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1043, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\GDAL\gdal2tiles.py", line 53, in <module>
    from osgeo import gdal
  File "C:\Users\Bold\AppData\Local\Programs\Python\Python37\lib\site-packages\osgeo\__init__.py", line 32, in <module>
    _gdal = swig_import_helper()
  File "C:\Users\Bold\AppData\Local\Programs\Python\Python37\lib\site-packages\osgeo\__init__.py", line 31, in swig_import_helper
    return importlib.import_module('_gdal')
  File "C:\Users\Bold\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: DLL load failed: The specified module could not be found.

As you can see, we receive a weird error. The .exe files work, but not the .py ones. It's most likely due to the Python bindings, but I believe that they are set up correctly.

4
  • Have your tried GISInternals binaries? See: gisinternals.com/index.html
    – Zoltan
    Commented Jun 17, 2020 at 18:59
  • @Zoltan The link that I posted was for GISInternals... Those are the binaries that I already downloaded
    – lve
    Commented Jun 17, 2020 at 19:03
  • I am using command lines gdal inside my Python scripts, but not the ones that use .py files.
    – FelixIP
    Commented Jun 17, 2020 at 20:43
  • I'm sorry, but that's not very helpful @FelixIP. As I stated, I need to use the python files and the other gdal commands (from core) already work.
    – lve
    Commented Jun 18, 2020 at 13:41

2 Answers 2

1

Try to run it like this python "C:\Program Files\GDAL\gdal2tiles.py". If it still fails then try to install python wheel from here https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal. That is what I did for my Windows setup and it is working fine:

  1. Install GDAL binaries from gisinternals
  2. Set GDAL environment variable
  3. Install GDAL wheel from ~gohlke
0

Since Python 3.8, you cannot load the dll directly from PATH. In order to tell GDAL to set the environment variable to force it,

USE_PATH_FOR_GDAL_PYTHON = YES

It should fix the DLL loading issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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