簡體   English   中英

在virtualenvwrapper環境中安裝GDAL

[英]Install GDAL in virtualenvwrapper environment

我試圖在virtualenvwrapper環境中安裝gdal(pip install gdal),但是我收到了這個錯誤:

  error: command 'gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for gdal
 Failed to build gdal

我也試過“pip install --no-install GDAL”,但沒有選擇--no-install

我該怎么辦 !?

是的,在venv中安裝GDAL是一件很麻煩的事。 方便的是,我剛剛寫了關於如何為我的顧問實驗室這樣做的文檔! 雖然我不夠精明,無法確定錯誤的確切原因,但我可以給你一些東西來嘗試解決它。

首先,確保在主機上安裝了gdal(即不在venv中)。 我只是運行以下內容:

sudo apt-get install libgdal1i libgdal1-dev libgdal-dev

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

現在,根據我的經驗,在venv中獲取python綁定的最簡單方法是使用pygdal 訣竅是獲得正確的版本! 為此,請激活您的虛擬環境並運行

pip install pygdal==1.11.3

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

Could not find a version that satisfies the requirement pygdal==1.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 ,但仍保持匹配的最高版本。 例如,在這種情況下,你將運行pip install pygdal==1.11.3.3

一旦pygdal成功安裝,你應該可以打電話

>>> from osgeo import gdal

如果有任何失敗,請告訴我,我會盡我所能來調整我的指示。 此外,如果您需要Proj.4,GEOS或Cartopy的幫助,我也有一些經驗。

使用pygdal

pd@asghar:~$sudo apt-get install python3-gdal 

pd@asghar:~$ virtualenv -p python3 test
Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/pd/test/bin/python3
Also creating executable in /home/pd/test/bin/python
Installing setuptools, pip, wheel...done.

pd@asghar:~$  gdal-config --version
2.1.3
pd@asghar:~$ test/bin/pip install pygdal==2.1.3
Collecting pygdal==2.1.3
  Could not find a version that satisfies the requirement pygdal==2.1.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, 1.11.5.3, 2.0.0.3, 2.0.1.3, 2.0.2.3, 2.0.3.3, 2.1.0.3, 2.1.1.3, 2.1.2.3, 2.1.3.3, 2.2.0.3)
No matching distribution found for pygdal==2.1.3
pd@asghar:~$ test/bin/pip install pygdal==2.1.3.3
Collecting pygdal==2.1.3.3
Collecting numpy>=1.0.0 (from pygdal==2.1.3.3)
  Using cached numpy-1.13.1-cp35-cp35m-manylinux1_x86_64.whl
Installing collected packages: numpy, pygdal
Successfully installed numpy-1.13.1 pygdal-2.1.3.3
pd@asghar:~$ source test/bin/activate
(test) pd@asghar:~$ python
Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from osgeo import gdal
>>> 

在MacOS上,首先進行brew安裝:

brew install gdal

然后做pip安裝:

pip install gdal

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM