1

I've been trying to install GDAL on Python 3.6.5 (64-bit) on Windows for the past hour, and nothing works.

I've visited some questions on SO, watched a video on YT, but none of them applies to my situation (which there's nothing special about it).

Can someone provide a step-by-step solution, preferably a tested one, so I can figure out what exactly I'm doing wrong?

I'm willing provide any OS setting info/screenshot if necessary.


Update: I'm trying to install GDAL to convert TIF (16-bit) files to JPG or PNG. Although I managed to install GDAL with the second method (at second try), I could not use gdal_translate. So not every GDAL lib/version works for me.


First method:

  • GDAL 2.3.0 (suggested here)

    • Dependencies:
      • libgdal (2.3.0 or greater) and header files (gdal-devel) (where/how do I get this?)
      • numpy (1.0.0 or greater) and header files (numpy-devel)
    • Requires "GDAL Windows Binaries". A Google search led me to this: DownloadingGdalBinaries – GDAL

      • Tried GISInternals -> Releases -> release-1911-x64-gdal-2-3-0-mapserver-7-0-7
      • Downloaded "gdal-203-1911-x64-core.msi" and "GDAL-2.3.0.win-amd64-py3.4.msi". (The latest release is for python 3.4?)
      • Installed "gdal-203-1911-x64-core.msi" to "C:\Program Files\GDAL".
      • In README, it says

        Add the installation directory bin folder to your system PATH...

        C:\gdalwin32-1.7\bin

        There is no "bin" folder in "C:\Program Files\GDAL". Folders in GDAL dir: "csharp", "gdal-data", "gdalplugins", "license", "projlib". So ...?

        I'm not even going to finish this because it seems outdated (I've emailed it's author about the description, so I hope it gets fixed). I followed the other steps, but it didn't work, obviously. Feel free to try it out.


Second method:

  • Gohlke Pythonlibs (suggested here)

    • Downloaded "GDAL-2.2.4-cp36-cp36m-win_amd64.whl"
    • At the top of the page, it says (I probably missed this in the first try)

      Many binaries depend on numpy-1.14+mkl and ...

      So I've downloaded "numpy-1.14.4+mkl-cp36-cp36m-win_amd64.whl" (it's in the same page)

    • Installed them:

      pip install numpy-1.14.4+mkl-cp36-cp36m-win_amd64.whl

      pip install GDAL-2.2.4-cp36-cp36m-win_amd64.whl

      and it worked (though I'm getting missing dll (ogr_FileGDB) error when using gdal_translate, so not using this)


I'll be updating this with the methods I've tried.

akinuri
  • 10,690
  • 10
  • 65
  • 102
  • show your errors better – Druta Ruslan Jun 06 '18 at 13:02
  • @zimdero There are multiple ways to install GDAL, and I've tried at least three of them. Which one do you want? I specifically said "preferably a tested one" because I want suggestions from experience. If we go examining the error messages, I believe we'll hit many walls because we don't even know if the installations I've tried applies to this specific python version. – akinuri Jun 06 '18 at 13:06
  • 1
    Uninstall your Python installation. Download and install the Anaconda installer from anaconda.com, it comes packages with Python and a lot of the most popular packages. Install GDAL by running the command `conda install gdal` – James Jun 06 '18 at 13:17
  • 2
    Two steps: 1. install conda. 2. use `conda install -c conda-forge gdal`. – Sraw Jun 06 '18 at 13:17
  • There are at least 4 methods listed [here](https://gis.stackexchange.com/questions/2276/installing-gdal-with-python-on-windows), which one did you try and what error came up with each one? – Adonis Jun 06 '18 at 13:22
  • I'll be updating the question with the methods I've tried, but it takes time as I try them again. So I hope you guys revisit the question. – akinuri Jun 06 '18 at 14:13
  • Try [pgmagick](https://www.lfd.uci.edu/~gohlke/pythonlibs/#pgmagick): `from pgmagick import Image;Image('cmyk-16.tif').write('cmyk-16.jpg')` worked for me. – cgohlke Jun 07 '18 at 19:39
  • @cgohlke I've just done a quick [test](https://github.com/akinuri/dump/tree/master/python/tif-cmyk-16/pgmagick-image-open-test) with pgmagick and it seems to be working (were able to open the troublesome tif (cmyk/16) file). I've posted another [question](https://stackoverflow.com/questions/50761021/how-to-open-a-tif-cmyk-16-bit-image-file) about opening the 16-bits tif files and I'll be updating it. I'll do further tests on Monday. If it all works out, I'll definitely ditch GDAL, and maybe Pillow too. – akinuri Jun 08 '18 at 16:36

1 Answers1

2

The prebuild GDAL version from conda-forge works great on windows 64 bit python 3.6.5

You can install Anaconda (or Miniconda)

After installing Anaconda, I usually use the Anaconda prompt instead of the regular windows command prompt.

(Optional) If you would like to isolate this in a specific environment

I would recomend using environments with anaconda so create some environment like this

conda create --name gdal_env python=3.6.5

activate gdal_env

Environments are not required, so you can skip this step and continue to installing gdal.

Install gdal

conda install -c conda-forge gdal

I have found conda-forge to be the (by far) easiest way to install GDAL on windows. If for some reason you are required to use another python distribution, i have found the prebuild binaries from here to work fine too https://www.lfd.uci.edu/~gohlke/pythonlibs/ if you follow this guide

the_cheff
  • 4,690
  • 3
  • 15
  • 23
  • I was hopeful about Anaconda/Miniconda, but I've faced further problems. My main reason to install GDAL is to open 16-bit TIF files. I could not do this in Pillow, and it was suggested that GDAL can do it. I've succesfully installed GDAL (using miniconda), but `gdal_translate` threw some errors. TIF to JPEG gives `JPEG driver doesn't support data type UInt16` error. TIF to PNG gives `libpng: profile 'ICC Profile': 'CMYK': invalid ICC profile color space`. I thought I could fix these later (because they seem solvable), so I installed Pillow (I also need it). – akinuri Jun 07 '18 at 08:16
  • `from PIL import Image` works fine, but `from PIL import ImageCms` threw an error: `ImportError: cannot import name '_imagingcms'`. I did not have this error with plain Python. I'm fed up with all these problems, so I'm dropping this for now. Although your answer and other comments solved **this** problem (so +1), my **actual** problem still remains. A side note: I've created a [repository](https://github.com/akinuri/dump/tree/master/tif-2-jpg) in case I (or someone else) revisit these problems. – akinuri Jun 07 '18 at 08:16
  • Have you tried to add the scale option which maps it into 8 bit range? If I add that convertion works fine. `gdal_translate -scale -of JPEG cmyk-16.tif cmyk-16.jpg` The scale options with zero arguments simply maps the 16 bit range into 8 bit. If you need some other scaling you can provide it as arguments to scale. I have just tried it on the images in your repo and it works fine – the_cheff Jun 07 '18 at 09:39
  • While scale alone works, it still has the warning, to get rid of that two, tell explicitly that you are converting to 8bit like this: `gdal_translate -scale -ot byte -of JPEG cmyk-16.tif cmyk-16.jpg` – the_cheff Jun 07 '18 at 10:54
  • Are you using GDAL of Anaconda? I've uninstalled it. I'm fixing the problematic TIFs (16-bit CMYK TIF) using Photoshop... After your reply, I thought that I don't need to associate GDAL with Python if I'm only gonna use `gdal_translate`. I've just installed `gdal-203-1911-x64-core.msi` from [here](http://www.gisinternals.com/query.html?content=filelist&file=release-1911-x64-gdal-2-3-0-mapserver-7-0-7.zip) and it didn't produce corrent images: [no-python](https://github.com/akinuri/dump/tree/master/tif-2-jpg/gdal/no-python) (repo update). Should I try different GDAL version? – akinuri Jun 07 '18 at 11:18
  • I've tried a different GDAL (OSGeo4W) and the result is the same. So what exactly am I doing wrong? (Updated repo again) – akinuri Jun 07 '18 at 11:42
  • I simply ran that command from within my Anaconda prompt, so it is GDAL installed with Anaconda. You can see the output images [here](https://ibb.co/kxZroT) and [here](https://ibb.co/eMm1No) – the_cheff Jun 07 '18 at 12:04
  • Are both of the the two links you've shared output images? Because the second one is the same as mine which is incorrect. I get the same result if I open the original image in Photoshop, invert colors, and move black towards white (through Levels). So can I say that GDAL doesn't convert correctly? If so, this has just became a GDAL-specific problem, and I might ask another question about this. – akinuri Jun 07 '18 at 13:14
  • Yes, both are outputs. What do you expect the output image to be? Do you expect gdal to convert from cmyk to rgb? If so you could do it by 2 commands like this: First create an RGB tif from the CMYK one `gdal_translate -scale -ot byte -of GTIFF cmyk-16.tif cmyk-out.tif -co PHOTOMETRIC=CMYK`. Then create the RGB jpg from the newly created tif `gdal_translate -of JPEG cmyk-out.tif cmyk-out.jpg`. If this is not the behaviour you are expecting i think you should update your question with what you need from the output file. [This is the output](https://ibb.co/dKAzso) – the_cheff Jun 07 '18 at 21:24
  • I decided to post a [question](https://stackoverflow.com/q/50761021/2202732) about this. I'd appreciate if you could take a look at it. – akinuri Jun 08 '18 at 12:51