39

I have tried to install geopandas via I python by running !pip install geopandas, but this fails with "python setup.py egg_info" failed with error code 1 and then Path to long directory. I read online that pyproj is required for geopandas and also tried to install it however no luck, similar error. Would anyone be able to point me in the right direction? Thank you.

Oh by the way, if this helps, I was able to install shapely, fiona, and Descartes using this method.

user3144095
  • 491
  • 1
  • 4
  • 3
  • What platform (linux/windows/max)? Would you be able to use conda to install it? – joris Dec 24 '15 at 14:02
  • Hi, I tried on both windows and mac and was unsuccessful with both. In terms of using conda, do you mean using the conda install command? – user3144095 Dec 27 '15 at 00:39
  • 3
    Yes, I mean the conda package magager: http://conda.pydata.org/docs/index.html. With this, you can install it from the ioos channel (`conda install -c ioos geopandas`) – joris Dec 27 '15 at 10:08
  • A no-conda and straightforward answer for Windows at https://stackoverflow.com/a/61418519/4194079 – keepAlive Apr 26 '20 at 16:37

17 Answers17

34

Thanks to the conda-forge community, geopandas is actually pretty easy to install on all platforms using the conda package manager (or: its dependencies, as this is the difficulty).

If you have conda, it is just:

conda install -c conda-forge geopandas

To install conda, you can install the Anaconda python distribution or miniconda: http://conda.pydata.org/docs/download.html

See the GeoPandas docs for more details, specifically on how to create a new environment with GeoPandas installed with settings to ensure this always works: https://geopandas.org/install.html#creating-a-new-environment

joris
  • 133,120
  • 36
  • 247
  • 202
  • After being stubborn and trying to persevere with `pip` ultimately the above worked in one go!! Just had to setup my proxy settings... – RK1 Mar 13 '19 at 10:48
  • Worked for me on windows. Should be the answer. – PraAnj Mar 17 '19 at 18:36
  • The website mentions to either stick to default install or conda-forge install? will this cause any issue since i almost everytime use default install. https://geopandas.org/install.html – Murtaza Haji May 27 '20 at 04:52
  • Yes, you best stick to one of both. But doing `conda install geopandas` (without conda-forge, but from the default channel) will also work fine. It may just take a bit longer to have the latest versions available there. – joris May 27 '20 at 18:21
  • 1
    Right now "conda install geopandas" and "conda install -c conda-forge geopandas" isn't working for me. What about the proxy settings? – Alvaro Morales Jul 10 '20 at 23:42
  • It isn't working for me either at the moment. – hbstha123 Aug 14 '21 at 14:10
  • This does not work anymore. – Niyousha Mohammadshafie Mar 04 '22 at 23:59
21

Getting to work geopandas is unfortuntaly not easy, the problem is that the dependencies are partly not working and you have to use older versions of Fiona and GDAL. The following packages work stable together:

GDAL: 1.11.2
Fiona: 1.6.0
Geopandas: 0.1.0.dev-

To install on ubuntu:

sudo apt-get install build-essential python-all-dev
wget http://download.osgeo.org/gdal/1.11.2/gdal-1.11.2.tar.gz
tar xvfz gdal-1.11.2.tar.gz
cd gdal-1.11.2
./configure --with-python
make
sudo make install

In addition, some Linux distributions require the shared library cache to be updated after install:

sudo ldconfig

Fiona and geopandas can be installed classic by:

sudo pip install Fiona==1.6.0
sudo pip install geopandas

Under windows

As @Marcus Williams states:

Download Fiona and GDAL Windows Binaries corresponding your python environment (32, 64bit and 2.7 3.3 etc. (from http://www.lfd.uci.edu/~gohlke/pythonlibs/) and go in cmd with cd to directory where downloaded files are and install the .whl files using the command

pip install filename.whl

Finally:

pip install geopandas
Philipp Schwarz
  • 18,050
  • 5
  • 32
  • 36
  • I have had some problems. First, the GDAL libraries available at the link you posted do not include the 1.11.2 version, so I had to grab the 2.0.3 (my Python version is 2.7.11 32 bit). Then, the `pip install geopandas` did not work because of `pyproj` (error code 1 in the cmd). Do you suggest downloading the exact versions you posted at the beginning of your answer? – FaCoffee Nov 19 '16 at 10:16
  • For most users it is recommended to use the python distribution Anaconda. Then you can follow the install guide http://geopandas.org/install.html or use anaconda cloud directly type: conda install -c ioos geopandas=0.2.1 If for some reason you do not want or can use Anaconda try the solution above, but note that since the packages are under heavy development, the solution stated may already be outdated. – Philipp Schwarz Nov 19 '16 at 20:51
  • Why is it so hard to deal with this package? Why haven't the developers fixed the dependencies? – FaCoffee Nov 20 '16 at 11:31
  • 2
    Note that the above is no longer up to date. GeoPandas currently works fine with the latest versions of gdal (> 2) and fiona (> 1.7). – joris Feb 07 '17 at 08:50
  • If you want to plot shape files (`*.shp`), you'll also need to install "descartes". – Kristada673 Oct 29 '18 at 02:37
14

I recently destroyed my Anaconda 5.2 distribution by trying to upgrade from Geopandas 0.3.0 to 0.4.0. I didn't notice that command conda install -c conda-forge geopandas wanted to upgrade a bunch of packages, downgrade others, and remove Anaconda 5.2.

Anyway, after reinstalling Anaconda 5.2 I ran into several Command "python setup.py egg_info" failed with error code 1 in <filepath> errors with no ways around it. I even tried installing Anaconda 5.2 on a different computer, still same error message.

I then stumbled on this website Geoff Boeing: Using geopandas on Windows. It did the trick for me. In case this link stops functioning at some point, I'll just copy-paste the contents below.

My notes: I installed cp36-versions from Gohlke as Anaconda 5.2 comes with Python 3.6.5. My Anaconda installation was installed by default to C:\Users\<Username>\AppData\Local\Continuum\anaconda3\Lib\site-packages so I used that as the environment variable.

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.x). 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

Update 21/03/2020: as of Anaconda 2020.02, rtree is now included in the distribution.

Vesanen
  • 387
  • 1
  • 5
  • 13
  • 1
    The above is not recommended *if* you are using Anaconda (if you are not using Anaconda, downloading wheels from Gohlke's site is indeed a way to get binary packages) – joris May 27 '20 at 18:22
  • @joris Would you kindly explain why? I consumed hours upon hours trying to get GeoPandas to work on Anaconda and my original post was the only way I managed to do it. This trouble has not alleviated since Anaconda 5.2 days. – Vesanen May 27 '20 at 19:15
  • 1
    To be clear, I fully understand and acknowledge the struggles to get GeoPandas installed, even with conda, and that this is very frustrating to loose hours on it. But *if* you use Anaconda, GeoPandas "should" install fine if you follow the instructions from https://geopandas.readthedocs.io/en/latest/install.html. If that's not the case, that's a bug that needs to be solved, and please then open an issue for it, so we can try to work it out. – joris May 28 '20 at 06:19
  • 1
    The problem with the above instructions is that they are 1) more difficult/onerous for the average user and 2) can go wrong in even more ways than with conda (eg those wheels are not compatible with wheels from PyPI, and you can easily get a mixture with pip, or not compatible with other conda packages). So while this might be a fallback strategy to try, it's IMO not the first thing people should try. And again, if you are not using Anaconda from the start, the above approach is certainly fine (actually even the only solution on Windows for certain packages that don't have wheels on PyPI). – joris May 28 '20 at 06:23
  • 1
    @joris Thank you for the elaborate answer. – Vesanen May 29 '20 at 19:40
5

After hours of failure (with WinError 126, "not a supported wheel on this platform" error, etc.), I've successfully installed pyproj and geopandas, and this is what I did:

  • Install descartes, pandas, fiona, shapely, pyproj first as they're required for geopandas.

  • For descartes and pandas, installation could be done directly with 'pip install descartes' or 'pip install pandas' from command line.

  • For fiona, shapely, pyproj:

    • Go to http://www.lfd.uci.edu/~gohlke/pythonlibs/

    • Download the corresponding .whl for your python version (e.g. Fiona-1.7.8-cp34-cp34m-win32.whl for Python 3.4). Important: download win32 version only, as win_amd64 version did not work (God knows why)

    • Install each package with 'pip install <path to download folder>Fiona-1.7.8-cp34-cp34m-win32.whl'
  • For geopandas:
Kevin
  • 338
  • 1
  • 3
  • 9
3

On Windows, I download (from http://www.lfd.uci.edu/~gohlke/pythonlibs/) and install the .whl files for GDAL, Fiona, pyproj, Shapely and Rtree using the command

pip install filename.whl

for each .whl file.

As a final step I run

pip install https://github.com/geopandas/geopandas/archive/master.zip

because I want the dev version of geopandas. The conda w/ ioos method looks easier - but I haven't tried it yet.

2

I'm using Window 10 and only had to reinstall Visual C++ 2015. Then i had to install fiona manually from here. After that i installed geopandas successfully.

1

To install geopandas on windows, you need to follow the below-mentioned steps: -

  1. You need to install GDAL wheel file using the link https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal . After visiting this link, download this file named "GDAL‑3.0.4‑cp37‑cp37m‑win32.whl" since it worked for me and then use the command "pip install c:\Users........\GDAL‑3.0.4‑cp37‑cp37m‑win32.whl" to successfully install GDAL which is the requirement of Geopandas.

  2. After installing the GDAL, you need to install a Fiona wheel file using the link https://www.lfd.uci.edu/~gohlke/pythonlibs/#fiona . Upon visiting this link, download the file named "Fiona‑1.8.13‑cp37‑cp37m‑win32.whl" since it is the supported wheel file for most of the windows users. After downloading this file, use the command "pip install c:\Users........\Fiona‑1.8.13‑cp37‑cp37m‑win32.whl".

  3. Lastly, run the command "pip install geopandas" and you are good to go!

NOTE: If the above-mentioned wheel file doesn't work for you, then try using alternate wheel files.

PIYUSH AGGARWAL
  • 239
  • 2
  • 3
1

When using pip to install GeoPandas, you need to make sure that all dependencies are installed correctly.

First install shapely, fiona, pyproj and rtree
Then you install geopandas

shapely and fiona provide binary wheels with the dependencies included for Mac and Linux, but not for Windows.

pyproj provides binary wheels with depencies included for Mac, Linux, and Windows.

rtree does not provide wheels.

pip install fiona, Pip install shapely,pyproj,rtree

Akash Desai
  • 498
  • 5
  • 11
1

You can install the dependencies including pyproj using the following command:

conda install pandas fiona shapely pyproj rtree descartes

To learn more about dependencies, I would refer to official guide. To install using pip use the following command:

pip install geopandas

You can also install geopandas using conda:

conda install geopandas

sometimes geopandas installed by conda is not the latest version. To have updated geopandas use the following command:

pip install geopandas --upgrade 
Dr. Arslan
  • 1,254
  • 1
  • 16
  • 27
1
  1. Go to https://www.lfd.uci.edu/~gohlke/pythonlibs/
  2. Download fiona, pyproj, GDAL and shapely with cp38
  3. Open command prompt where you downloaded those wheel files
  4. Run - pip install <file_name> (for ex. pip install Fiona-1.8.19-cp38-cp38-win_amd64.whl)
  5. Now download geopandas and install like mentioned above.

Fiona, GDAL, Shapely, and pyproj are dependencies to install geopandas. Therefore, install them before installing geopandas. Hope this works for you as well!

1

Installing geopandas is not easy because of the lots of dependencies involved. You have to manually download files from this website.

Follow the steps:

  1. Step1: first go-to site where all packages listed. CTRL + F, then type GDAL and download "GDAL-3.4.2-cp39-cp39-win_amd64.whl". [filename may differ]

  2. Step2: Same for all files. CTRL + F, then download "pyproj-3.3.0-cp39-cp39-win_amd64.whl", "Fiona-1.8.21-cp39-cp39-win_amd64.whl", "Shapely-1.8.1.post1-cp39-cp39-win_amd64.whl", and "geopandas-0.10.2-py2.py3-none-any.whl". I am not sure but follow this order while installing files. Also, make sure put all those files in the same location for easing to install all files.

  3. Step3: I am not using anaconda. pip install GDAL-3.4.2-cp39-cp39-win_amd64.whl same for all files in

  4. Step4: Finally, a quick sanity check. python import geopandas as gpd

code_conundrum
  • 529
  • 6
  • 12
0

problem(Windows 10 x64, Python 3.4+):

1.Install Visual C++ 2010 Express (download). (Do not install Microsoft Visual Studio 2010 Service Pack 1 )

2.Remove all the Microsoft Visual C++ 2010 Redistributable packages from Control Panel\Programs and Features. If you don't do those then the install is going to fail with an obscure "Fatal error during installation" error.

then: pip install pyproj

0

I was running into this same problem (it might not be fully over) but I'll show you what I did. I basically did the same things that a lot of people had mentioned and then by accident stumbled upon something that worked well.

Steps involved:

  1. Remove the following packages: fiona, gdal, pyproj, geoplot, rtree via the command 'conda remove fiona' etc. in Anaconda Prompt
  2. Install geoplot in Anaconda Prompt: conda install geoplot -c conda-forge

This has geopandas and all it's dependencies built into it (fiona, gdal, pyproj, etc). I'm not sure this is an ultimate fix but it worked for me! If this doesn't work for you, I would recommend following Vesanen's instructions as that also worked for me for awhile. The problem I ran into was once I had geopandas installed I couldn't install the package geoplot without Spyder crashing.

colidyre
  • 4,170
  • 12
  • 37
  • 53
Brian
  • 1
0
  1. First install GDAL wheel file using the command pip install GDAL.
    You can see the documentation here.
  2. Then use the command conda install geopandas.
    You can see the documentation here.

I was using Jupyter notebook and this worked for me.

Richard Shi
  • 625
  • 1
  • 9
  • 21
0

I have Windows 10 and I have same problem with geopandas.

You can try this solution BUT remember that before install geopandas you also need install GDAL (same method that on link above via .whl for GDAL works fine). It wasn't worked for me first time, but worked when I reinstall fiona to 1.8.6 version (because v.2+ gets errors)

I wanted to install geopandas, but before it I had to install Fiona. And this was my solution:

  1. Download binary gdal from here. I choosed this: release-1911-x64-gdal-2-4-4-mapserver-7-4-3.

    1.1. You need to download 1 zip-file: release-1911-x64-gdal-2-4-4-mapserver-7-4-3-libs.zip

    1.2. Extract this to local path, e.g. "C:\\Users\\Jack\\Gdal"

  2. Download Fiona from master. You can download zip now

  3. Unpacking Fiona-master.zip, e.g. "C:\\Users\\Jack\\Fiona-master"

  4. Open CMD, open dir "Fiona-master": chdir "C:\\Users\\Jack\\Fiona-master" and run this (with your paths):

    python setup.py build_ext -I"<PATH_TO_GDAL_INCLUDE_DIR>" -lgdal_i -L"<PATH_TO_GDAL_LIB_DIR>" install --gdalversion 2.1

    In my case:

    python setup.py build_ext -I"C:\\Users\\Jack\\Gdal\\include" -lgdal_i -L"C:\\Users\\Vasilev_EN\\Downloads\\Gdal\\lib" install --gdalversion 2.1

  5. I didn't have cython and got error, so: pip install cython

  6. Again try run long string from (4)

  7. After success: pip install geopandas worked fine

Jackssn
  • 1,346
  • 1
  • 14
  • 16
0

I succecssfully installed geopandas using pip on Ubuntu 18.04.5 running Python 3.9 with the following package versions working together.

pandas==1.3.5
numpy==1.21.5
Fiona==1.8.20
pyproj==3.3.0
rasterio==1.2.10
Shapely==1.8.0
geopandas==0.10.2

To install the packages run pip install <package==version>

mvdl
  • 1
0

I'm writing a dockerized application in 2022 and wanted to avoid adding conda build dependencies (as it resulted in a very large container with long build time just to run a single package!). The most straight-forward answer I've found is adding the following packages to your requirements.txt file:

numpy
pandas
shapely
fiona
six
cython
pyproj
geopandas

testing this in a container allowed me to remotely read a shapefile and print the first entry successfully

# python3 test.py
STATEFP                                                      01
COUNTYFP                                                    061
COUNTYNS                                               00161556
AFFGEOID                                         0500000US01061
GEOID                                                     01061
NAME                                                     Geneva
NAMELSAD                                          Geneva County
STUSPS                                                       AL
STATE_NAME                                              Alabama
LSAD                                                         06
ALAND                                                1487908432
AWATER                                                 11567409
geometry      POLYGON ((-86.19347599999999 31.192213, -86.12...
Name: 0, dtype: object

Letting it install just using the package names without a version gave me these package versions:

# pip3 freeze | egrep -i '(numpy|pandas|shapely|fiona|six|cython|pyproj|geopandas)'
Cython==0.29.26
Fiona==1.8.20
geopandas==0.10.2
numpy==1.22.1
pandas==1.3.5
pyproj==3.3.0
Shapely==1.8.0
six==1.16.0

Taking this approach reduced my build time to 44.2s

Source: geopandas github issue


Here's the size comparison between the conda container (gpd-test) for gpd vs the python container, since I mentioned it was a large container with a long build time.

$ docker image ls | egrep '(REPO|gpd)'
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
gpd-api      latest    55b0022c6aaf   4 hours ago   386MB
gpd-test     latest    5fc768d10a3a   4 weeks ago   3.2GB
sanigirl
  • 433
  • 3
  • 19