
gdal
我在 Ubuntu Jammy (22.04) 上安裝 Python 模組時遇到問題。我已經libgdal-dev
安裝gdal-bin
在系統上了。我安裝了gdal module
指定相同版本的gdal
ie 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)