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.
- Navigate to the binaries (this version) and download the following:
gdal-300-1911-x64-core.msi
for the core (do typical install) andGDAL-3.1.0.win-amd64-py3.7.msi
for the python bindings. - Add
C:\Program Files\GDAL
to your PATH under system variables. Move it to the very top. - Add these two system variables:
GDAL_DRIVER_PATH
=C:\Program Files\GDAL\gdalplugins
andGDAL_DATA
=C:\Program Files\GDAL\gdal-data
- Press OK and navigate to your command prompt.
- Type in
gdalinfo --version
. This should outputGDAL 3.1.0dev, released 2019/99/99
- 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.