geopandas - How to install it on Windows

Installing geopandas on Windows can be tough, with all version conflicts, .whl files, pip packages, there are a lot of issues, but, here is a complete tutorial on how to write it.

Installing geopandas on Windows can be intimidating, so, going through the tutorials and documentation, here is how to install it and use it on Windows.

First, we need to install Python, pip and its perquisites. We will be using Python 3.7 (NOTE THAT YOU CANNOT USE Python 3.8 AT THE MOMENT OF WRITING THIS ARTICLE, SINCE FIONA.whl IS STILL NOT AVAILABLE FOR Python 3.8) .

So, hop to python's website and download the binaries here. When downloaded, install it the regular way and set the installation directory to be root of your Windows drive: C:\Python37. Also, add Python to the PATH (you will be asked during the installation). Once done, we can start installing pip things.

So, open up your CMD as Administrator and type:

python -m pip install pip --upgrade && pip install setuptools --upgrade

This will install pip and necessary pip packages.

Now, we will start installing geopandas.
First, we will not be installing dependencies through pip, but from .whl files. The dependencies that we will need are and can be found on these urls: GDAL, Fiona, pyproj, rtree and shapely. The links I provided are to the website where you can find .whl files for each architecture and each Python version. Since we have Python 3.7, we will only need to know our architecture type, whether it is a 32bit or 64bit. Since the download I provided is using 32bit Python, please download the specified files bellow .whl package:
GDAL: GDAL‑2.4.1‑cp37‑cp37m‑win32.whl
Fiona: Fiona‑1.8.6‑cp37‑cp37m‑win32.whl
pyproj: pyproj‑2.4.0‑cp37‑cp37m‑win32.whl
rtree: Rtree‑0.8.3‑cp37‑cp37m‑win32.whl
shapely: Shapely‑1.6.4.post2‑cp37‑cp37m‑win32.whl

Please NOTE: GDAL version needs to be 2.4.1 since it compatible with all other .whl files. If you choose 3.0.1, this won't work

Alright, great, now, we need to install them, one by one.
I suggest creating virtual env for this, but, you can do it however you want, so, first, we need to install GDAL:

pip install C:\Download\GDAL2.4.1cp37cp37mwin32.whl

When we have done this, we need to set ENVIRONMENT VARIABLE. To do this, please right click on "This PC"->"Properties"->"Advanced System Settings"->"Environment Variables" and to the top of this screen, you will see "Path" in the list. Select it and click "Edit". After that, click on "New" and add it like:

Now we can continue with installation of other .whl files. Close the CMD and reopen it again so that ENV variable can kick in.

pip install C:\Download\Fiona1.8.6cp37cp37mwin32.whl
pip install C:\Download\pyproj2.4.0cp37cp37mwin32.whl
pip install C:\Download\Rtree0.8.3cp37cp37mwin32.whl
pip install C:\Download\Shapely1.6.4.post2cp37cp37mwin32.whl

Alright, so, we are done with the installation, let us check if GDAL is working.
Close and open your CMD and type:

gdalinfo --help-general

If all is good, you should see:

There is an error when installing GDAL that needs to be fixed. Basically, GDAL will tell you that it cannot find the module, but the module is there:
ERROR 1: Can't load requested DLL: C:\project\virtualenv\Lib\site-packages\osgeo\gdalplugins\ogr_FileGDB.dll
Even tough the file is there, this error will be thrown.
So, to fix this, we need to move that file (Move, not Copy) out of the gdalplugins and into the osgeo folder.
Now, when you run again the command from above, you will get no errors.

In order to test this in Python code, create a script and run it:

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

So, this is how to install and use GDAL on Windows! Happy coding!

Comments (0)

Leave a comment

Dire Solutions Logo Dark Vertical