问题描述
我尝试在virtualenvwrapper环境中安装gdal(pip install gdal),但出现此错误:
I tried to install gdal (pip install gdal)in virtualenvwrapper environment but I got this error :
error: command 'gcc' failed with exit status 1
----------------------------------------
Failed building wheel for gdal
Failed to build gdal
我也尝试了"pip install --no-install GDAL",但是没有选项--no-install
I tried also "pip install --no-install GDAL" but there is nooption --no-install
我该怎么办!?
推荐答案
是的,在venv中安装GDAL很麻烦.方便地,我刚刚为我的顾问实验室编写了有关如何执行此操作的文档!虽然我不够聪明,无法找出导致错误的确切原因,但我可以提供一些方法来尝试解决该问题.
Yes, installing GDAL in a venv is a doozy. Conveniently, I just wrote up the documentation on how to do so for my advisor's lab! While I am not savvy enough to pinpoint the exact cause of your error, I can give you a bunch of things to try to fix it.
首先,请确保在主机上安装了gdal(即,不在venv中).我只是运行以下内容:
First, ensure you have gdal installed on the host (i.e. not in a venv). I just run the following:
sudo apt-get install libgdal1i libgdal1-dev libgdal-dev
现在运行gdal-config --version
以获取apt-get
为您提供的版本.例如我得到1.11.3
Now run gdal-config --version
to get the version that apt-get
provided you with. For example I get 1.11.3
现在,根据我的经验,在venv中获取python绑定的最简单方法是使用pygdal
.诀窍是获得正确的版本!为此,请激活您的虚拟环境并运行
Now, the easiest way in my experience to get the python bindings in a venv is using pygdal
. The trick is to get the right version! To do so, activate your virtual environment and run
pip install pygdal==1.11.3
,但请用从gdal-config --version
获得的任何内容替换该版本.注意:您可能会看到一条错误消息
but replace the version with whatever you got from gdal-config --version
. Note: you may get an error that says
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 pygdal==1.11.3.3
If that happens, run the pip install
again but with the highest version that still matches. e.g. in this case you would run pip install pygdal==1.11.3.3
成功安装了pygdal
后,您应该可以致电
Once pygdal
has been successfully installed, you should be able to call
>>> from osgeo import gdal
请让我知道是否有任何故障,我将尽我所能来调整说明.另外,如果您需要Proj.4,GEOS或Cartopy的帮助,我也有一些经验.
Please let me know if anything fails and I'll do what I can to adjust my instructions. Also, if you need help with Proj.4, GEOS, or Cartopy, I have some experience there too.
这篇关于在virtualenvwrapper环境中安装GDAL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!