I am trying to use the OSGeo library and GDAL Python bindings in a script for Python 3.7.7 on MacOS 10.15.4 Catalina. However, when I try to compile the script, I receive the following error as soon as I import from the OSGeo module:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/osgeo/__init__.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/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: dlopen(/usr/local/lib/python3.7/site-packages/osgeo/_gdal.cpython-37m-darwin.so, 2): Library not loaded: /usr/local/opt/cfitsio/lib/libcfitsio.8.dylib
Referenced from: /usr/local/opt/osgeo-gdal/lib/libgdal.27.dylib
Reason: image not found
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 1, in <module>
import countries
File "/Users/adamsamec/Dropbox/Work/Eurofly/eurofly-reverse-geocoder/countries.py", line 4, in <module>
from osgeo import ogr
File "/usr/local/lib/python3.7/site-packages/osgeo/__init__.py", line 32, in <module>
_gdal = swig_import_helper()
File "/usr/local/lib/python3.7/site-packages/osgeo/__init__.py", line 31, in swig_import_helper
return importlib.import_module('_gdal')
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_gdal'
Here are the steps I've taken to install the osgeo and GDAL libraries, partially using the Homebrew package manager for Mac:
- Downloaded and installed this GDAL 2.4 Complete package.
- In Terminal, run the following commands:
pip3 install gdal
brew tap osgeo/osgeo4mac
brew install osgeo-gdal-python
Looks like the GDAL library is not properly installed because when I run gdalinfo
, I get the following error:
dyld: Library not loaded: /usr/local/opt/cfitsio/lib/libcfitsio.8.dylib
Referenced from: /usr/local/bin/gdalinfo
Reason: image not found
zsh: abort gdalinfo
Do you have any ideas what I am doing wrong?