14

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:\users\isaac\appdata\local\programs\python\python35-32\python.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('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\Isaac\AppData\Local\Temp\pip-fxko2gfx-record\install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.5
    copying gdal.py -> build\lib.win32-3.5
    copying ogr.py -> build\lib.win32-3.5
    copying osr.py -> build\lib.win32-3.5
    copying gdalconst.py -> build\lib.win32-3.5
    creating build\lib.win32-3.5\osgeo
    copying osgeo\gdal.py -> build\lib.win32-3.5\osgeo
    copying osgeo\gdalconst.py -> build\lib.win32-3.5\osgeo
    copying osgeo\gdalnumeric.py -> build\lib.win32-3.5\osgeo
    copying osgeo\gdal_array.py -> build\lib.win32-3.5\osgeo
    copying osgeo\ogr.py -> build\lib.win32-3.5\osgeo
    copying osgeo\osr.py -> build\lib.win32-3.5\osgeo
    copying osgeo\__init__.py -> build\lib.win32-3.5\osgeo
    Fixing build\lib.win32-3.5\gdal.py build\lib.win32-3.5\ogr.py build\lib.win32-3.5\osr.py build\lib.win32-3.5\gdalconst.py build\lib.win32-3.5\osgeo\gdal.py build\lib.win32-3.5\osgeo\gdalconst.py build\lib.win32-3.5\osgeo\gdalnumeric.py build\lib.win32-3.5\osgeo\gdal_array.py build\lib.win32-3.5\osgeo\ogr.py build\lib.win32-3.5\osgeo\osr.py build\lib.win32-3.5\osgeo\__init__.py
    Skipping optional fixer: ws_comma
    Fixing build\lib.win32-3.5\gdal.py build\lib.win32-3.5\ogr.py build\lib.win32-3.5\osr.py build\lib.win32-3.5\gdalconst.py build\lib.win32-3.5\osgeo\gdal.py build\lib.win32-3.5\osgeo\gdalconst.py build\lib.win32-3.5\osgeo\gdalnumeric.py build\lib.win32-3.5\osgeo\gdal_array.py build\lib.win32-3.5\osgeo\ogr.py build\lib.win32-3.5\osgeo\osr.py build\lib.win32-3.5\osgeo\__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:\users\isaac\appdata\local\programs\python\python35-32\python.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('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\Isaac\AppData\Local\Temp\pip-640gw1ah-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Isaac\AppData\Local\Temp\pip-build-07o7k41s\gdal

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:\Users\Isaac\AppData\Local\Programs\Python\Python35-32, which is where it was placed when I installed PyCharm, but that folder and the /Scripts/ folder inside are in my PATH.

After a bit more research I'm wondering if it's because I'm using Python 3.5? I tried rolling back to Python 3.4 and see if it changes anything, but 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.

2
  • Do refer to this SO question stackoverflow.com/questions/6009506/…
    – aliasm2k
    Commented Dec 22, 2015 at 5:47
  • I tried running through that but it didn't seem to work. I'll give it another try tomorrow when I'm hopefully a little more clear-headed.
    – wfgeo
    Commented Dec 22, 2015 at 6:04

5 Answers 5

17

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.

9
  • you may need to conda upgrade numpy after you install gdal this way. on my windows install, it downgraded numpy. Commented Dec 23, 2015 at 20:42
  • @user1269942 When you create a new environment there should be no downgrade, because there is no NumPy installed yet (in this environment). Commented Dec 23, 2015 at 20:45
  • OK, I see...cool. I guess I always have sklearn/numpy etc installed no matter what. Environments...sounds good for allowing other to reproduce your results. Commented Dec 24, 2015 at 1:06
  • 1
    Ok I'm not understanding this. I ran through all of the steps and then tried to import gdal (In the same cmd window) and it still says "no module named gdal". Also, am I installing gdal to a specific environment? How do I access this environment from my IDE? I just want it to be installed by default. Is it a whole new python installation? I'm very confused.
    – wfgeo
    Commented Dec 24, 2015 at 20:43
  • 1
    This line 2.0.0 np110py34_0 defaults says that you can use Python 3.4 conda create -n gdal_test python=3.4 with NumPy 1.10 (will be installed automatically) and gdal 2.0.0. Commented Dec 25, 2015 at 19:37
7

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):

6
  • Using pip install GDAL-2.2.4-cp36-cp36m-win_amd64.whl from Gohlke Pythonlibs worked for me on Python 3.6.5. Thanks :D
    – cfrostte
    Commented May 30, 2018 at 16:14
  • @emi I'm using Python 3.6.5 64-bit and can't install GDAL. Can you elaborate on the steps you took?
    – akinuri
    Commented Jun 6, 2018 at 12:45
  • @akinuri I simply runed pip install GDAL-2.2.4-cp36-cp36m-win_amd64.whl on my cmd under Windows 10. You have to download the .whl file first of course and make sure that you are on the same path than the .whl; you can download that file from this link. What error do you are having?
    – cfrostte
    Commented Jun 6, 2018 at 22:43
  • @emi See my question. Although I managed to install GDAL, I couldn't use gdal_translate. I'm getting an error saying "module could not be loaded" (probably missing dll: ogr_FileGDB)
    – akinuri
    Commented Jun 7, 2018 at 7:08
  • @akinuri Sorry, I have no idea what's going on with your code; I have no experience in using GDAL. I simply executed a copy and paste code and it was executed successfully. Maybe your are trying to execute an old code? Maybe if you does not use gdal_translate library on your code execution?
    – cfrostte
    Commented Jun 7, 2018 at 14:05
1

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.

1

I got it to work using:

conda install -c conda-forge gdal
0

This worked for me (for my Windows 7): Download the wheel file for GDAL from the following link (it has up to Python 3.8)

http://pypi.naturalcapitalproject.org/simple/gdal/index.html

I downloaded the wheel file (GDAL-3.0.4-cp37-cp37m-win_amd64.whl) which is suitable for Python 3.7 installed on Windows 64-bit.

Go to the scripts folder of the Python folder and install the wheel file:

pip install GDAL-3.0.4-cp37-cp37m-win_amd64.whl

If the downloaded wheel file is on a specific folder, add the path to the pip command, for example:

pip install c:/users/myaccount/desktop/GDAL-3.0.4-cp37-cp37m-win_amd64.whl

Lastly, do not change the name of the downloaded wheel file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.