8

I'm having problems installing the gdal library for python. I use a Windows 7 and have WinPython 2.7.9.2 which runs Python 2.7.9. I'd like to use gdal + Python for raster manipulation.

I've read that PIP is the preferred way for installing packages on windows and that its packed with Python 2.7.9. I've edited my PATH environment variable to include pip and python:

;c:\~\WinPython-32bit-2.7.9.2\python-2.7.9\Scripts\;c:\~WinPython-32bit-2.7.9.2\python-2.7.9\

so I can now run both python and pip directly from command prompt.

The error appears when I type

c:\>pip install gdal

which gives:

C:\~\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Include\xlocale(342) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
extensions/gdal_wrap.cpp(2855) : fatal error C1083: Cannot open include file: 'cpl_port.h': No such file or directory
error: command 'C:\\~\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\cl.exe' failed with exit status 2

So apparently something called 'cpl_port.h' is missing. This is also described in this question where it's suggested that header files cannot be found. The solution provided in that thread is however LINUX based and incompatible with my Windows.

I'm not quite sure how to proceed from here so should I forego PIP and try another route?

I've verified that PIP works by installing some other packages, so the problem seems to be with gdal.

  • A simple workflow is to install Python from Windows msi installer and GDAL + python bindings also from msi installers which can be downloaded from gisinternals.com. – user30184 Mar 26 '15 at 22:40
  • Hi, thanks for your comment. Can you elaborate a bit? I hear the term 'bindings' a lot, but am clueless on what you mean there. Likewise, what's MSI installer? Mind that I've already have Python installed and rather not install it again if I can avoid it. – HDR Mar 26 '15 at 22:44
  • MSI stands for Microsoft installer. For user it is a file ending with .msi that you double click and then it starts to install. With bindings you can call GDAL code that is written in C/C++ from Python files.opensuse.org/opensuse/en/e/eb/…. If you have Python already installed you can use it. – user30184 Mar 27 '15 at 5:54
4

GDAL is actually a set of toos written in C. As such it needs to be compiled prior to installation, and Windows doesn't come with a C compiler. As such your easiest bet is to download and install pre-compiled binaries of the library. The easiest place to get binaries is from Christoph Gholke who offers a package of the complete GDAL library as well as the Python bindings.

Finally, if you're looking to play with modifying rasters in Python I'd strongly recommend installing rasterio (binaries available from Gholke as well) which is a much nicer wrapper around GDAL and might be a lot easier to use.

  • Hi, thanks for taking the time to answer. I'll look into your reply tomorrow, it's getting late here. Cheers! – HDR Mar 26 '15 at 22:47
  • How would the gdal installation know where I installed the binaries? – Školstvo Jul 19 '17 at 10:04
0

you have to download Microsoft Visual C++ Compiler for Python 2.7 from https://www.microsoft.com/en-us/download/details.aspx?id=44266 and install. then edit your Gdal system path

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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