Having trouble installing GDAL for python

Question:

Let me start by saying that I have searched for help this problem and gone through the numerous threads that I have found, and none of them have worked, or I wasn’t able to understand what they are saying to do.

Once such thread is here: Python GDAL package missing header file when installing via pip

I was able to run

pip install --no-install GDAL

But then I was instructed to “cd into ENV/build/GDAL”. I know what cd means but I have no idea where this /ENV/build/GDAL diretory would be located and there is no more information about it in the post, or in the post that it references.

The core problem is just that I want to install GDAL for use in Python. I tried

pip install GDAL, and it failed with this output:

    Collecting GDAL
  Using cached GDAL-2.0.1.tar.gz
Installing collected packages: GDAL
  Running setup.py install for GDAL
    Complete output from command c:usersisaacappdatalocalprogramspythonpython35-32python.exe -c "import setuptools, tokenize;__file__='C:\Users\Isaac\AppData\Local\Temp\pip-build-4kmkv1_4\GDAL\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('rn', 'n'), __file__, 'exec'))" install --record C:UsersIsaacAppDataLocalTemppip-fxko2gfx-recordinstall-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating buildlib.win32-3.5
    copying gdal.py -> buildlib.win32-3.5
    copying ogr.py -> buildlib.win32-3.5
    copying osr.py -> buildlib.win32-3.5
    copying gdalconst.py -> buildlib.win32-3.5
    creating buildlib.win32-3.5osgeo
    copying osgeogdal.py -> buildlib.win32-3.5osgeo
    copying osgeogdalconst.py -> buildlib.win32-3.5osgeo
    copying osgeogdalnumeric.py -> buildlib.win32-3.5osgeo
    copying osgeogdal_array.py -> buildlib.win32-3.5osgeo
    copying osgeoogr.py -> buildlib.win32-3.5osgeo
    copying osgeoosr.py -> buildlib.win32-3.5osgeo
    copying osgeo__init__.py -> buildlib.win32-3.5osgeo
    Fixing buildlib.win32-3.5gdal.py buildlib.win32-3.5ogr.py buildlib.win32-3.5osr.py buildlib.win32-3.5gdalconst.py buildlib.win32-3.5osgeogdal.py buildlib.win32-3.5osgeogdalconst.py buildlib.win32-3.5osgeogdalnumeric.py buildlib.win32-3.5osgeogdal_array.py buildlib.win32-3.5osgeoogr.py buildlib.win32-3.5osgeoosr.py buildlib.win32-3.5osgeo__init__.py
    Skipping optional fixer: ws_comma
    Fixing buildlib.win32-3.5gdal.py buildlib.win32-3.5ogr.py buildlib.win32-3.5osr.py buildlib.win32-3.5gdalconst.py buildlib.win32-3.5osgeogdal.py buildlib.win32-3.5osgeogdalconst.py buildlib.win32-3.5osgeogdalnumeric.py buildlib.win32-3.5osgeogdal_array.py buildlib.win32-3.5osgeoogr.py buildlib.win32-3.5osgeoosr.py buildlib.win32-3.5osgeo__init__.py
    Skipping optional fixer: ws_comma
    running build_ext
    building 'osgeo._gdal' extension
    error: [WinError 2] The system cannot find the file specified

Command "c:usersisaacappdatalocalprogramspythonpython35-32python.exe -c "import setuptools, tokenize;__file__='C:\Users\Isaac\AppData\Local\Temp\pip-build-07o7k41s\gdal\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('rn', 'n'), __file__, 'exec'))" install --record C:UsersIsaacAppDataLocalTemppip-640gw1ah-recordinstall-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:UsersIsaacAppDataLocalTemppip-build-07o7k41sgdal

Can someone please help me with this? I’m completely lost and have no idea what to do about this.

I’m wondering if maybe it’s because my python installation is in a funny place? It’s installed at C:UsersIsaacAppDataLocalProgramsPythonPython35-32, which is where it was placed when I installed PyCharm, but that folder and the /Scripts/ folder inside are in my PATH.

Edit: After a bit more research I’m wondering if it’s because I’m using Python 3.5? I’ll try rolling back to Python 3.4 and see if it changes anything

Edit 2: Nope, no luck, it still fails and tells me

error: Microsoft Visual C++ 10.0 is required (Unable to find vcvarsall.bat)

I tried to install Microsoft Visual C++ 10.0 and it just told me that there was already a newer version on my computer.

Asked By: wfgeo

||

Answers:

Probably the easiest way to install such kind of libraries is conda. Get and install Miniconda as user, not root. Now, create a new environment and install gdal into it:

conda create -n gdal_test python=3.5
activate gdal_test
conda install gdal

You need to stay inside this shell window. i.e. th prompt should like this (gdal_test). Start Python:

python
>>> import gdal

Note: On Linux and Mac OS X use source activate gdal_test.

To find out what versions of gdal are available, type:

conda search gdal

An output like this:

gdal

      ....

               2.0.0               np110py34_0  defaults

means gdal 2.0.0 is available for Python 3.4 and needs NumPy 1.10.

Answered By: Mike Müller

On Windows the easiest way to install GDAL is to use pre-built binaries unless you have special needs that require building GDAL from source. Apart from conda, as mentioned by @Mike Müller, there are three common sources for GDAL Windows binaries (with Python bindings):

Answered By: Kersten

To install GDAL on windows, you need to follow the below-mentioned step: –

  1. You need to install GDAL wheel file using the link https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal . After visiting this link, download this file named “GDAL‑3.0.4‑cp37‑cp37m‑win32.whl” since it worked for me and then use the command “pip install c:Users……..GDAL‑3.0.4‑cp37‑cp37m‑win32.whl” to successfully install GDAL which is the requirement of Geopandas.

NOTE: If the above-mentioned wheel file doesn’t work for you, then try using alternate wheel files.

Answered By: PIYUSH AGGARWAL

This helped me :
https://mothergeo-py.readthedocs.io/en/latest/development/how-to/gdal-ubuntu-pkg.html

#!/usr/bin/env bash

sudo add-apt-repository ppa:ubuntugis/ppa && sudo apt-get update
sudo apt-get update
sudo apt-get install gdal-bin
sudo apt-get install libgdal-dev
export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal
pip install GDAL
Answered By: Reut
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.