Using geopandas on Windows

projected-shapefile-gps-coordinatesThis guide was updated in June 2016 to reflect changes to the dependencies and the ability to install with Python wheels.

I recently went through the exercise of installing geopandas on Windows and getting it to run. Having learned several valuable lessons, I thought I’d share them with the world in case anyone else is trying to get this toolkit working in a Windows environment (also see this GitHub gist I put together).

It seems that pip installing geopandas works fine on Linux and Mac. However, several of its dependencies have C extensions that cause compilation failures with pip on Windows. This guide gets around that issue. For preliminaries, I have this working on Windows 7, 8, and 10. My Python environments are Anaconda, 64-bit, with both Python 2.7 and 3.5. I’m running geopandas version 0.2 with GDAL 2.0.2, Fiona 1.7.0, pyproj 1.9.5.1, and shapely 1.5.16.

The best bet on Windows is to install Python wheels when possible, because they contain pre-compiled extensions. The conda package manager that comes with Anaconda does this for packages available in its repository. Alternatively, Christoph Gohlke at the Laboratory for Fluorescence Dynamics at UC Irvine maintains a large library of Python wheels for Windows.

Installing geopandas the easy way

First, try to install geopandas the easy way using conda and conda-forge. From your command prompt, run:

conda install -c conda-forge geopandas

If that doesn’t work, install it the manual but foolproof way…

Installing geopandas and its dependencies manually

  1. First and most important: do not try to directly pip install or conda install any of the dependencies – if you do, they will fail in some way later, often silently or obscurely, making troubleshooting difficult. If any are already installed, uninstall them now.
  2. Download the wheels for GDAL, Fiona, pyproj, rtree, and shapely from Gohlke. Make sure you choose the wheel files that match your architecture (64-bit) and Python version (2.7 or 3.5). If Gohlke mentions any prerequisites in his descriptions of those 5 packages, install the prerequisites now (there might be a C++ redistributable or something similar listed there).
  3. If OSGeo4W, GDAL, Fiona, pyproj, rtree, or shapely is already installed, uninstall it now. The GDAL wheel contains a complete GDAL installation – don’t use it alongside OSGeo4W or other distributions.
  4. Open a command prompt and change directories to the folder where you downloaded these 5 wheels.
  5. pip install the GDAL wheel file you downloaded. Your actual command will be something like: pip install GDAL-1.11.2-cp27-none-win_amd64.whl
  6. Add the new GDAL path to the windows PATH environment variable, something like C:\Anaconda\Lib\site-packages\osgeo
  7. pip install your Fiona wheel file, then your pyproj wheel file, then rtree, and then shapely.
  8. Now that GDAL and geopandas’s dependencies are all installed, you can just pip install geopandas from the command prompt, like this (click for full-size):

Install geopandas on windows with dependencies gdal, fiona, pyproj, shapely

Verifying the geopandas installation

Close the command prompt. To test GDAL, re-open the command prompt and run:

gdalinfo --help-general

This command will display GDAL usage instructions if it’s installed properly and the Windows PATH variable is pointing correctly to its install directory. Lastly, test the Python bindings and geopandas itself. From a Python interpreter, run the following lines of code:

from osgeo import gdal, ogr, osr
from fiona.ogrext import Iterator, ItemsIterator, KeysIterator
from geopandas import GeoDataFrame
gdal.VersionInfo()

If each of these lines of code runs successfully without errors, then geopandas is successfully installed and ready to be used. Here’s a simple example of using geopandas with matplotlib to plot point data over a shapefile basemap:

most-isolated-projected

For more advanced examples, see this tutorial on R-tree spatial indexing with geopandas, and an intro to the OSMnx package that uses geopandas to work with OpenStreetMap street networks. You may also be interested in this simple GitHub gist I put together on a quick way to install geopandas as part of a Python spatial science stack, with Miniconda.

26 thoughts on “Using geopandas on Windows”

    1. Yes. Pandas is just a data analysis library for python. It is spatially agnostic. Geopandas basically spatializes pandas. It lets you add a geometry column to your pandas dataframes so you can work with shapefiles, geojson, etc. And it supports pretty robust spatial analysis and projections. I give a run-through of some of these capabilities in my post on projecting spatial data with python.

  1. Thanks for sharing your steps! I have been pulling out my hair out trying to get many of these packages installed with conda. I was wondering if you know how/where to get/build a conda package for geoJSON. I have been trying to figure it out but I am a newbie and haven’t had much success.

    I was curious if you used the conda convert command to install the binaries from Christoph Gohlke’s site?

    I would like to complete this session from SCIPY 2013 https://github.com/kjordahl/SciPy2013 but am having difficulties setting up the proper enivorment/installing Windows versions of many of the packages. Thank you!

  2. I haven’t used conda convert, but I agree that the conda package manager is definitely the easiest way to work with Python packages, especially in a Windows environment. Although the python geojson package doesn’t exist in the conda repository, I was able to pip install it without any trouble on my Windows machine (Win 8.1, x64). Geopandas can also do some useful work with geojson formats. Most of my other work with geojson I do with ogr2ogr.

  3. Holy crap. Thank you. Just wasted a lot of time trying to get this all installed to no avail. This made it much simpler. Cheers!

  4. I have a silly question. Could somebody please explain step 5? I am not sure what to add where. Thanks in advance!

    1. You need to edit your Windows PATH environment variable, so that it contains the path to the folder where GDAL is installed. The process for editing your PATH varies by your version of Windows, so you should Google your version’s instructions. Here’s a generic one that looks like Windows 7: http://www.howtogeek.com/118594/how-to-edit-your-system-path-for-easy-command-line-access/

      You need to add the GDAL path, which will be something like “C:\Anaconda\Lib\site-packages\osgeo” to your PATH variable.

  5. Hi Geoff,

    fantastically helpful, thanks!

    I’m trying to get it all working in Python 2.7 (Anaconda) on Windows 7 and having trouble with fiona 1.6.3 and GDAL 2.0.2 which I got from Gohlke’s site as you recommended.

    “gdalinfo” shows ogr_FileGDB.dll missing

    “fiona.ogrtext” import attempts show “DLL load failed”

    thanks for any tips

    1. Not sure. I haven’t experienced those errors. Some things to check: make sure the versions of the packages are right for each other (ie, correct dependency versions). Make sure no previous GDAL instances were installed before you installed Gohlke’s. And, make sure the system PATH variable is updated properly.

        1. Thanks, I’m having the same issue and figure it’s because I installed GDAL v 2.0.2 rather than 1.11. But how did you install v 1.11? The wheel doesn’t appear to be on the Grohl site any more.

          1. Dave Grohl should definitely start a Python packaging web site 🙂

            FWIW, I’m using GDAL 2.0.2 now and it all works fine for me. I’ve got it working on both Python 2.7 and Python 3.5, with GDAL 2.0.2, pyproj 1.9.5.1, shapely 1.5.16, fiona 1.7.0, and geopandas 0.2.

            If you’re having trouble, I suggest starting with a new, clean Python environment or set up a virtual environment (for example with conda) and then install only these packages per my instructions. Make sure it’s all working, then add additional packages, making sure nothing breaks.

  6. Thanks! Great links and great info. Had obscure package installation errors but this got me up and running with geopandas.

    Wondering why I need to add the /path/osgeo/ to my PATH. Geopandas seems to work fine without this.

    Also, very minor update: looks like the correct syntax is now:
    gdalinfo –help-general

    1. The conda-forge technique was broken (due to a broken dependency) last time I updated these instructions, but yes if conda-forge is working for your environment, go that route. It’s easy and clean!

      1. Hi Geoff, and thanks.

        Actually, I installed geopandas with conda-forge and I still had problems after installing the other packages that rely on the gdal libraries (fiona, shapely, rasterio, etc.). It mainly has to do with the ways in which each package deals with the gdal dll files (dll hell). At the end of the day, the gdal libraries are written in C++, that’s the real problem. Even with OSX, things can get screwy real fast. Python developers have made great progress, however, with packages like fiona, shapely, rasterio, and more.

        Who knows maybe I did something wrong on the install, but after spending an entire day messing with it, I reverted back to your method and it worked like a charm. I think I am convinced that when using any packages that rely on the gdal libraries, it’s best pip install the wheels for everything, even when using Anaconda. That’s the beauty of Anaconda because you can create a ‘pip-only’ python 2 environment (apart from ‘conda create’) for the geospatial packages, and then create other environments if needed. This leaves the geospatial environment clean and uncluttered.

        Here’s a pretty cool tutorial from last year’s scipy 2015:
        https://www.youtube.com/watch?v=HzPSVwyP2Y0

        github repo:
        https://github.com/kjordahl/SciPy-Tutorial-2015

Leave a Reply

Your email address will not be published. Required fields are marked *