Install GDAL in virtualenvwrapper environment
Install GDAL in virtualenvwrapper environment
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
I tried also "pip install --no-install GDAL" but there is nooption --no-install
what should I do !?
pip install gdal==1.9
libgdal-dev
CPPFLAGS
LDFLAGS
Ubuntu 14.04 and also my gdal version on Os is 2.0.0 and I tried to install gdal==2.0.0 but does not work !
– GeoCom
Aug 18 '15 at 8:41
You need
gdal-dev
and gdal-bin
packages. Running pip
with CFLAGS="-I/usr/include/gdal" pip install gdal
might also be necessary.– dhke
Aug 18 '15 at 8:45
gdal-dev
gdal-bin
pip
CFLAGS="-I/usr/include/gdal" pip install gdal
Thank you. It worked for me !
– GeoCom
Aug 18 '15 at 8:53
3 Answers
3
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.
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
Now run gdal-config --version
to get the version that apt-get
provided you with. For example I get 1.11.3
gdal-config --version
apt-get
1.11.3
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
pygdal
pip install pygdal==1.11.3
but replace the version with whatever you got from gdal-config --version
. Note: you may get an error that says
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
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
pip install
pip install pygdal==1.11.3.3
Once pygdal
has been successfully installed, you should be able to call
pygdal
>>> from osgeo import gdal
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.
Thanks for the explanation. Especially for the "Could not find a version that satisfies the requirement pygdal==1.11.3 (from versions: ....)" error.
– ni8mr
Sep 14 '17 at 5:15
saved me!! thanks
– Reiion
Oct 24 '17 at 13:28
These instructions really helped me to get Kartograph.py working, thank you
– colmjude
Feb 2 at 4:16
Cheers mate. I think the mentioning the version worked for me!
– Salman Ghauri
Apr 6 at 8:00
Thanks, medley56 this was helpful
– Abhijay Ghildyal
May 22 at 11:46
use 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
>>>
It worked for me on OSX HighSIerra and Python3.6:
pip install pygdal
and then from osgeo import gdal
.– Duccio A
Dec 2 '17 at 21:59
pip install pygdal
from osgeo import gdal
On MacOS, first do brew install:
brew install gdal
Then do pip install:
pip install gdal
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Which OS is this on? pyGDAL is a little bit difficult with virtualenvs since it requires the appropriate C++ library already installed on the system. You also should match versions (i.e. if your OS has libgdal 1.9,
pip install gdal==1.9
is your friend). For Debian-based systems you also needlibgdal-dev
installed. And then there's sometimes alsoCPPFLAGS
andLDFLAGS
.– dhke
Aug 18 '15 at 8:10