Categories
Data

Using geopandas on Windows

projected-shapefile-gps-coordinatesThis guide was written in 2014 and updated slightly in November 2020.

I recently went through the exercise of installing geopandas on Windows. 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. It seems that pip installing geopandas usually works fine on Linux and Mac. However, several of its dependencies have C extensions that can cause compilation failures with pip on Windows. This guide gets around that issue.

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/Miniconda does this for packages available in its repository, including channels like conda-forge. Alternatively, Christoph Gohlke at UC Irvine maintains a large library of Python wheels for Windows.

Installing geopandas the easy way

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

conda config --prepend channels conda-forge
conda create -n geo --strict-channel-priority geopandas jupyterlab

Then activate your new geo environment and run some code. 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.

65 replies on “Using geopandas on Windows”

Hi nice. So is there anything “pandas” can’t do but “geopandas” can handle easily with?

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.

Haven’t read all the comments so I apologize if this is a repeat.

Do try “””conda install -c conda-forge geopandas”””” before going into the more in-depth stuff.

I defaulted to wheels first as that is how I’ve installed fiona historically. Was setting up an environment on a computer where I do not have admin rights and the wheel strategy was not successful. So do try the snippet above. This even updated packages installed from Gohlke’s wheels.

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!

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.

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!

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

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.

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

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.

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.

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.

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

Hi awesome work. Do we still need to do all of the wheels for Windows 10? I thought that was a Windows 7 issue? Thanks.

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!

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

I just want ask that when I do import fiona, it raise a error:cannot import name compat,why?

Hi,
Thx for the great post. I try to run virtualenv for every project (thus installing geopanda manually).
How would you go about adding the GDAL to the system PATH? (to which installation?)

I don’t comment usually but this post was very helpful. Thanks for sharing your learnings and struggles.

Hi, I operate as you have said, but I come across some exceptional problems:
I. When I use the command: gdalinfo –help-general, in the Python environment, it turns out that name ‘gdalinfo’ is not defined
II. I excute the statement: from fiona.ogrext import Iterator,ItemsIterator,KeysI, and get the the ImportError: cannot import name KeysI
Addition: the module you have refered can be imported

Hey Geoff,

Would you recommend scripting the manual process over the automatic one?

Either one may work. The easy process may have conflicting libraries that cause odd errors if it isn’t installed in a virtual environment. The manual process in comparison is a bit of a pain, but pretty safe.

Thanks for this man. I am a bit of a newbie and I learned a lot from this post. Thanks for sharing!

This cmd works for me; ‘conda install -c ioos geopandas’.
This is a better second alternative to; conda install -c conda-forge geopandas.

system: win7-64(intel) on Anaconda

Hello old post. Python bindings seem to work fine so far, but gdalinfo on cmd line gives:

ERROR 1: Can’t load requested DLL: …\anaconda3\envs\python3packt\Lib\site-packages\osgeo\gdalplugins\ogr_FileGDB.dll
193: %1 is not a valid Win32 application.

though I installed all 64 bit versions.

Python says : Python 3.6.6 | packaged by conda-forge | (default, Jul 26 2018, 11:48:23) [MSC v.1900 64 bit (AMD64)] on win32

Perhaps that has something to do with it.

the conda install is not working for me

using manual install, how do I “uninstall” OSGeo4W, GDAL, Fiona, pyproj, rtree, or shapely, I see their folders, do i just delete any folder with any mention of them?

I did the uninstallation just by writing: “conda uninstall ” (e.g.: conda uninstall OSGeo4W) . Then I manually installed the packages following Prof. Boeings instructions. And it worked for me.

hello, I am using python 3.6 version. For geopandas in python 3.6, can I use update version of all dependencies??. please reply

No, you have to use the version that are adaptable with your python version

I spend more than 3 hours to install geopandas. Finally, this kind instruction works for me.
Thank you so much.

Thank you so much for writing this! I spent a day installing geopandas on Windows 2 years ago but didn’t make notes on what in the end made it work. Just had to do it again and was so annoyed with myself that I didn’t write down what I did 2 years ago! You’ve saved my day :)

Thank you very much gboing, this was extremely helpful. I´ve been trying to install gdal in Windows 10 and your method worked just fine. One question please, at Christoph Gohlke’s webpage says that the FileGDB plugin requiresneed Esri’s FileGDB API 1.3. I downloaded FileGDB API 1.3 but not sure what to do with it?

The error mentioned above by Peter Donovan: “gdalinfo” shows ogr_FileGDB.dll missing” is because GDAL cant find the file “FileGDBAPI.dll” but I´m not sure how to install it.

I’m so close! Added GDAL to PATH, pip installed all the whls successfully, then pip installed geopandas. But when I try to check gdalinfo –help-general I get:

ERROR 1: Can’t load requested DLL: C:\Python37\Lib\site-packages\osgeo\gdalplugins\ogr_FileGDB.dll
126: The specified module could not be found.

But when I go into the folder, that file exists! Any thoughts? Thanks!

I have the same error. Installed all whls successfully and get same error, except below the error message the help print does show. I tried to test in IDE with the sample code and not working either. Any thoughts?

This is a great help! However, I am still having problems. I am running windows 10. I am completely new to installing whl files and still new to python. I have spent hours researching and trying different methods and nothing seems to work.

ERROR: Could not find a version that satisfies the requirement GDAL-3.0.4-cp36-cp36m-win_amd64 (from versions: none)
ERROR: No matching distribution found for GDAL-3.0.4-cp36-cp36m-win_amd64

Hello,

I followed every step but I am receiving this error:

ImportError Traceback (most recent call last)
in ()
—-> 1 import geopandas as gpd

C:\ProgramData\Anaconda3\lib\site-packages\geopandas__init__.py in ()
—-> 1 from geopandas.geoseries import GeoSeries # noqa
2 from geopandas.geodataframe import GeoDataFrame # noqa
3 from geopandas.array import _points_from_xy as points_from_xy # noqa
4
5 from geopandas.io.file import read_file # noqa

C:\ProgramData\Anaconda3\lib\site-packages\geopandas\geoseries.py in ()
7 from pandas.core.internals import SingleBlockManager
8
—-> 9 from pyproj import CRS, Transformer
10 from shapely.geometry.base import BaseGeometry
11 from shapely.ops import transform

ImportError: cannot import name ‘CRS’

This is also possible in anaconda environments! I could activate an environment in the Anaconda prompt and then install geopandas in multiple different environments using the manual installation without conda forge.

Thank you so much for this! My jupyter-lab suddenly stopped working this morning, and after almost six hours of installing and reinstalling packages, I finally managed to get things working again. I was literally jumping for joy and running around in my room when things finally worked out. Thank you very very much for these clear instructions.

Leave a Reply to zhuiCancel reply