矩池雲安裝gdal五種解決方案


1、最快最靠譜的是conda

conda install gdal

命令行conda/pip search gdal查看版本,選擇合適的版本,例如:conda search gdal 命令行conda/pip
install gdal=版本號,注意加上版本號,否則可能安裝上老版本(windows/linux都可用。例如:conda install
gdal=3.0.0

2、源碼編譯

(1)下載GDAL安裝包(在官網上下載即可 http://www.gdal.org ,官網有下載鏈接但不知道為什么有時候會打不開,http://download.osgeo.org/gdal/)

wget http://download.osgeo.org/gdal/2.0.0/gdal-2.0.0.tar.gz
tar -xzvf gdal-2.0.0.tar.gz
cd gdal-2.0.0
./configure(./configure --with-python 可以讓python版本的gdal在make時安裝)
make
make install(如果有權限不足不能寫入的話就sudo make install)

(2)將依賴的動態庫和靜態庫添加到LD_LIBRARY_PATH環境變量中去。編輯bash的用戶配置文件:

vim ~/.bashrc

添加:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

(3)直接運行gdalinfo,如果出現下面圖片則是安裝成功。

(4)讓GDAL可以在python下使用

進入到/你的目錄/gdal-2.0.0/swig/python目錄下

python setup.py build
python setup.py install

在python環境中運行:import osgeo

可能會提示的錯誤:ImportError: No module named _gdal

使用sudo find / -name gdal.py查找所在位置

然后用import sys;sys.path查看是否包含當前路徑,若不包含,添加到路徑中,如下圖所示:

find / -name gdal.py
gedit /etc/profile
/etc/profile

3、pip install直接安裝pygdal

感覺網上大部分的教程都不好使,直接pip install gdal會報錯,通過安裝pygdal就能用。

本人ubuntu16.04

安裝依賴庫:

apt-get install libgdal1i libgdal1-dev libgdal-dev

現在運行gdal-config --version來獲取apt-get為您提供的版本。 例如,我得到1.11.3

pip install pygdal==1.11.3

但用gdal-config --version中的任何內容替換版本。 注意:您可能會收到錯誤消息

Could not find a version that satisfies the requirement pygdal1.11.3
(from versions: 1.8.1.0, 1.8.1.1, 1.8.1.2, 1.8.1.3, 1.9.2.0, 1.9.2.1,
1.9.2.3, 1.10.0.0, 1.10.0.1, 1.10.0.3, 1.10.1.0, 1.10.1.1, 1.10.1.3, 1.11.0.0, 1.11.0.1, 1.11.0.3, 1.11.1.0, 1.11.1.1, 1.11.1.3, 1.11.2.1, 1.11.2.3, 1.11.3.3, 1.11.4.3, 2.1.0.3) No matching distribution found for pygdal
1.11.3

如果發生這種情況,請再次運行pip install,但仍保持匹配的最高版本。

例如 在這種情況下:

pip install pygdal==1.11.3.3

安裝成功后

>>> from osgeo import gdal

4、stackoverflow

記錄一下:參考這個安裝成功了

https://stackoverflow.com/questions/38630474/error-while-installing-gdal

gdal-config --version

Then run this commands:

pip install --download="some_path" GDAL
cd some_path
tar -xvzf GDAL-<version>.tar.gz
cd GDAL-<version>
python setup.py build_ext --include-dirs=/usr/include/gdal/

5、conda直接安裝fiona

該方法是在遇到:

ImportError: libgeos-3.4.2.so: cannot open shared object file: No such
file or directory

這個問題時發現的,github上也有人遇到了相同的問題,應該是gdal的相關依賴出現了版本的問題,在把libgeos安裝到3.4.2版本后還會有其他的依賴問題,可以嘗試逐個解決,最方便的方法就是:

conda uninstall gdal

卸載重新安裝fiona

conda install fiona

fiona: Fiona is designed to be simple and dependable. It focuses on
reading and writing data in standard Python IO style and relies upon
familiar Python types and protocols such as files, dictionaries,
mappings, and iterators instead of classes specific to OGR. Fiona can
read and write real-world data using multi-layered GIS formats and
zipped virtual file systems and integrates readily with other Python
GIS packages such as pyproj, Rtree, and Shapely. Fiona is supported
only on CPython versions 2.7 and 3.4+.

然后anaconda會把相關的庫都安裝好。

參考文章

Ubuntu18.04 + python 環境安裝gdal的若干方法和遇到的問題

ubuntu-GDAL安裝踩坑記


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM