gdal
我在 Ubuntu Jammy (22.04) 上安装 Python 模块时遇到问题。我在系统上安装了libgdal-dev
和。我安装了 并指定了 的相同版本,即。如果不指定版本,我无法使用 进行安装。gdal-bin
gdal module
gdal
pip install gdal==3.4.1
pip
当我在 Python 中运行时from osgeo import gdal
,出现以下错误消息:
ImportError: /home/fabiola/miniconda3/lib/python3.9/site-packages/zmq/backend/cython/../../../../.././libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /lib/libgdal.so.30)
During handling of the above exception, another exception occurred:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-5-61e0eefce4de> in <module>
----> 1 from osgeo import gdal
~/miniconda3/lib/python3.9/site-packages/osgeo/__init__.py in <module>
43
44
---> 45 _gdal = swig_import_helper()
46 del swig_import_helper
47
~/miniconda3/lib/python3.9/site-packages/osgeo/__init__.py in swig_import_helper()
40 traceback_string = ''.join(traceback.format_exception(*sys.exc_info()))
41 raise ImportError(traceback_string + '\n' + msg)
---> 42 return importlib.import_module('_gdal')
43
44
~/miniconda3/lib/python3.9/importlib/__init__.py in import_module(name, package)
125 break
126 level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)
128
129
ModuleNotFoundError: No module named '_gdal'
我最近升级到了 Ubuntu 22.04,这已经导致一些软件出现问题,需要重新安装。我不知道这个元素在这种情况下是否也相关。
答案1
确保您已export CPLUS_INCLUDE_PATH=/usr/include/gdal
正确export C_INCLUDE_PATH=/usr/include/gdal
设置。
答案2
对于那些着急的人来说:
# ubuntu 22.04
sudo apt-get install libgdal-dev gdal-config
export CPLUS_INCLUDE_PATH=$(gdal-config --cflags | sed 's/-I//')
export C_INCLUDE_PATH=$(gdal-config --cflags | sed 's/-I//')
pip install GDAL==$(gdal-config --version)