我按照这些说明在运行 Amazon Linux 2 的新 AWS t3a.large EC2 实例上安装 GDAL 3.2.0 以用于 python2.7 程序。安装似乎已经成功,但是from osgeo import gdal
在 python 中使用时,我收到以下错误消息:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib64/python2.7/site-packages/osgeo/__init__.py", line 32, in <module>
_gdal = swig_import_helper()
File "/usr/local/lib64/python2.7/site-packages/osgeo/__init__.py", line 31, in swig_import_helper
return importlib.import_module('_gdal')
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named _gdal
当我搜索文件 _gdal* 时,我得到:
/tmp/gdal-3.2.0/swig/python/build/lib.linux-x86_64-2.7/osgeo/_gdalconst.so
/tmp/gdal-3.2.0/swig/python/build/lib.linux-x86_64-2.7/osgeo/_gdal.so
/tmp/gdal-3.2.0/swig/python/build/lib.linux-x86_64-2.7/osgeo/_gdal_array.so
/usr/local/lib64/python2.7/site-packages/osgeo/_gdalconst.so
/usr/local/lib64/python2.7/site-packages/osgeo/_gdal.so
/usr/local/lib64/python2.7/site-packages/osgeo/_gdal_array.so
这是我所做的一切:
sudo yum groupinstall "Development Tools"
sudo yum install python-pip
sudo pip install numpy
sudo yum install cpp.x86_64 sqlite-devel.x86_64 libtiff.x86_64 cmake3.x86_64 -y
cd /tmp
wget https://download.osgeo.org/proj/proj-6.1.1.tar.gz
tar -xvf proj-6.1.1.tar.gz
cd proj-6.1.1
./configure
sudo make
sudo make install
cd ..
wget https://github.com/OSGeo/gdal/releases/download/v3.2.0/gdal-3.2.0.tar.gz
tar -xvf gdal-3.2.0.tar.gz
cd gdal-3.2.0
./configure --with-proj=/usr/local --with-python
sudo make
sudo make install
which gdalinfo; gdalinfo --version
GDAL 3.2.0, released 2020/10/26
export PYTHONPATH=$PYTHONPATH:/usr/local/lib64/python2.7/site-packages
任何帮助将不胜感激。