Error installing geopandas:" A GDAL API version must be specified " in Anaconda
Asked Answered
Q

17

113

This error raised while installing geopandas. I've looking for its solution on the web, but none of them really explain what happened and how to solve it.. This is the full error:

    Collecting geopandas
  Using cached https://files.pythonhosted.org/packages/24/11/d77c157c16909bd77557d00798b05a5b6615ed60acb5900fbe6a65d35e93/geopandas-0.4.0-py2.py3-none-any.whl
Requirement already satisfied: shapely in c:\users\alvaro\anaconda3\envs\tfdeeplearning\lib\site-packages (from geopandas) (1.6.4.post2)
Requirement already satisfied: pandas in c:\users\alvaro\anaconda3\envs\tfdeeplearning\lib\site-packages (from geopandas) (0.20.3)
Collecting fiona (from geopandas)
  Using cached https://files.pythonhosted.org/packages/3a/16/84960540e9fce61d767fd2f0f1d95f4c63e99ab5d8fddc308e8b51b059b8/Fiona-1.8.4.tar.gz
    Complete output from command python setup.py egg_info:
    A GDAL API version must be specified. Provide a path to gdal-config using a GDAL_CONFIG environment variable or use a GDAL_VERSION environment variable.

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\Alvaro\AppData\Local\Temp\pip-install-oxgkjg8l\fiona\
Quintessa answered 17/2, 2019 at 15:20 Comment(13)
What happens if you type gdal-config --version?Writeoff
That line "gdal-config --version" didn't work on anaconda prompt neither jupyter notebook. But doing "conda list" in the current problem environment . gdal version is 2.2.4Quintessa
so you're using anaconda or pip? for both? did you install gdal separately?Writeoff
I tried to install geopandas with pip in the jupyter notebook and gdal with conda in the anaconda promptQuintessa
Really bad idea to mix env managers like that. I would uninstall what you've done with pip and conda, and try again just with conda - see my answer below.Writeoff
I created a new environment with conda and with python 3.7.2. Then I installed geopandas with "conda install -c conda-forge geopandas" . but when I import geopandas in jupyter notebook it says that "ModuleNotFoundError: No module named 'geopandas'"Quintessa
And also "geopandas" in sys.modules is false.. that's weird because I've just installed it..Quintessa
make sure you're in the new env in your notebook. You can run !conda info --envs and see which one is marked with a starWriteoff
I checked that and still the error remainsQuintessa
Please mark a response as "Question Answered". Thanks!Ideation
Simply updating my pip worked. python -m pip install --upgrade pip then pip install geopandasFerriage
Do the new releases of geopandas have changed anything? They did for me.Antenatal
You should consider accepting https://mcmap.net/q/193374/-error-installing-geopandas-quot-a-gdal-api-version-must-be-specified-quot-in-anaconda as answer, because it's the best and recommended solution when working with anaconda and/or geopandas :-)Insist
I
166
pip install wheel
pip install pipwin

pipwin install numpy
pipwin install pandas
pipwin install shapely
pipwin install gdal
pipwin install fiona
pipwin install pyproj
pipwin install six
pipwin install rtree
pipwin install geopandas

here are the source links: http://geopandas.org/install.html#installation https://pip.pypa.io/en/latest/user_guide/#installing-from-wheels https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy

If you still have problems, consider uninstalling the above (pip uninstall) and reinstalling.

Ideation answered 19/11, 2019 at 22:40 Comment(16)
It worked wonders in a virtual env. I was installing fiona and gdal manually in a terminal. Now I just followed this sequence and voela!Baliol
The first line is pip install wheels or pip install wheel?Dagan
pip install wheelIdeation
How to set the path for pipwin installed library. since I am inside my virtualenv, the package installed using pipwin are not listed inside venv/lib/site packagesCold
Thank you, for some reason, this is the only solution that worked for me from this entire page of solutions!Foregoing
I should add that I also needed to install geos and decartes.Foregoing
It seems that I can't install numpy with pipwin if six is not installed first: ModuleNorFoundError: No module named 'sixChrista
Can`t believe this is the best solution. Isn't possible to try something just with GDAL?Christa
The only solution that has worked for me on windows thanks!Zeeba
If you get an SSL error [SSL: CERTIFICATE_VERIFY_FAILED] on MacOs while installing on of the libraries this worked for me exerror.com/…Apomixis
What are the main differences between pipwin and pip? I hope they are both working through pypi.org...?Molluscoid
Gohlke's wheel repository is going to shut down soon. How can we solve those issues without it?Carburize
@Carburize That will affect Win users running on Windows only. They can move on to use WSL to install and run it on Linux.Menorrhagia
this sequence is just superb!Fordo
This answer is not helpful since pipwin is only suitable for windowsSchuss
The following worked for me in docker: https://mcmap.net/q/195698/-docker-build-fails-when-trying-to-install-fiona-using-python-imageSchuss
R
48

I solved this problem by running the following commands:

pip install pipwin
pipwin install gdal
pipwin install fiona
pip install geopandas

Works successfully on Windows.

Refugiorefulgence answered 28/8, 2020 at 11:45 Comment(7)
Just wanted to add that I succesfully installed gdal and fiona using pipwin instead of pip.Velodrome
I can also confirm that pipwin worked for installing gdal and fiona pip install pipwin pipwin install gdal pipwin install fiona pip install geopandasFlyspeck
Can you specify a default timeout option with pipwin? I'm getting timeout errors.Selway
Thanks. It works on Windows, Python 3.9. Install gdal and finona with pipwin first. The rest is with pip.Butterflies
This worked fine for me. I was trying to install geopandas on a virtual python environment on windows 10 and i could not get set it up. But using @Marcelo's list of commands worked perfect.Rattoon
Also worked for me as well !Redeemable
Works for me too. But I have to ask... Who is "Christoph Gohlke" (creator of pipwin)? What happens when his site which pipwin is pulling the unofficial prebuilt binary's from goes down? Is this the only way to install geopandas without dragging along a conda or miniconda env?Precedential
W
29

Geospatial Data Abstraction Library (GDAL) is a library designed for vector geospatial data formats. It's a prerequisite for installing Fiona, the Python API for OGR (which doesn't really stand for anything), which is in turn a prerequisite for Geopandas. On UNIX-like systems the gdal-config script tells Fiona stuff about your particular gdal installation.

It seems that your gdal-config is not in one of the usual places on your PATH, so Fiona was unable to find it.

If you're using Anaconda, best is to remove gdal with conda remove gdal and then do a fresh conda install geopandas.

As a general rule, if you're using Conda you should never use pip to install something inside it unless you're absolutely sure conda offers no support for it. (Many package can be found on conda by specifying the right channel - -c argument.) And specifically in the case of geopandas, the maintainers recommend using conda over pip, since pip requires you to install the dependencies correctly.

Writeoff answered 17/2, 2019 at 15:45 Comment(3)
How can I share you the new error code? I has to be with this: ImportError: DLL load failed: No se puede encontrar el módulo especificado.Quintessa
this is from conda? try conda install -c conda-forge geopandasWriteoff
super great detailed answer to get the concepts clear, Thanks.Delafuente
S
18

I had a lot of issues myself installing geopandas, mostly showing error when downloading fiona and gdal. I did every step above and did a conda install geopandas but failed. The only thing worked for me is to install fiona and gdal wheel separately.

go to the link by Christoph: gohlke:https://www.lfd.uci.edu/~gohlke/pythonlibs/#fiona

  • You can search for fiona and gdal wheel files. Make sure you choose the file as per your python version, if it is 3.7 then there would be cp37.
  • Download the file
  • go to command prompt, put cd and then pip install , install GDAL wheel file, then fiona, then just do pip install geopandas.

This solution worked for me.

Swadeshi answered 30/7, 2020 at 16:5 Comment(1)
worked like a charm, whl downloaded from lfd.uci.edu/~gohlke/pythonlibs/#fiona and installed it manually. Thank you very muchAstrea
F
10

To install gdal, I followed the following steps:

  1. downloaded the version that satisfies my computer (64 bit) from https://www.lfd.uci.edu/~gohlke/pythonlibs/ . The file was GDAL-3.1.4-cp37-cp37m-win_amd64.whl

  2. Put the file in a folder on the desktop.

  3. From cmd, i moved to that directory and executed python -m pip install GDAL-3.1.4-cp37-cp37m-win_amd64.whl

  4. This is followed by installing fiona the same way: python -m pip install Fiona-1.8.18-cp37-cp37m-win_amd64.whl

  5. For shapely, i executed conda install -c conda-forge shapely

  6. After that, i was able to install keplergl as usual: pip install keplergl

  7. install descartes: conda install -c conda-forge descartes (or python -m pip install descartes).

In this way, i didn't have to play around with the 'Environmental Variables' as this may affect other programs Cheers..

Farrago answered 1/12, 2020 at 9:13 Comment(0)
L
9

Installing geopandas

Geopandas has very complex multi-language dependencies, some of which need to be built with consistent compiler versions across packages. Because of this, the geopandas docs recommend installing using conda in a new environment using conda-forge only. Here are some general best practices to keep in mind:

  1. conda is the recommended installation method. You can install geopandas from pip or source, but it's going to be a bumpy ride and it's not recommended. If you're installing conda for the first time, I recommend you start with miniconda (or better yet miniforge, a conda-forge-first miniconda variant), not anaconda, to keep your base env lean.
  2. When using conda, you should not mix and match conda channels.
  3. When installing geopandas, try creating a fresh environment rather than installing into your base environment. If you have anaconda installed, it comes with a large number of packages from the "defaults" channel installed in your base environment. I recommend deleting anaconda and installing miniconda, then installing into a new environment.
  4. Try to create a new environment with everything you plan to use all at once rather than iteratively modifying the environment. In other words, if you want to use geopandas with scikit_learn, folium, and rasterio, install them together with a single conda create command
  5. As a last resort, delete your conda installation and re-install miniconda. Desperate times call for desperate measures, and this usually resolves gnarly installation nightmares.

To create a fresh conda environment in which you install all necessary dependencies at the same time, using the conda-forge channel:

conda create -n my-geopandas-env -c conda-forge geopandas [all other packages you need]

For example, I might set up an environment with something along the lines of...

conda create -n my-geopandas-env -c conda-forge python=3.9 \
   ipython ipykernel geopandas scipy seaborn fiona matplotlib cartopy

Bundling your installations into a single environment creation step like this reduces the chance of packages falling out of sync. To speed this process up, you could first install mamba or mambaforge, a faster drop-in replacement for conda, into your base environment and then run the above commands with mamba instead of conda.

Generally, it's best to avoid installing much of anything in your base environment (cross-environment system utilities like mamba are some of the few exceptions). If you already have a complex base environment (maybe you started with anaconda rather than miniconda) this may be the time to delete your entire conda installation and start from scratch (I know that's terrifying... sorry! but it'll save you heartache in the future). mamba is great for speeding this process up.

Connecting your editor to the conda environment

Once you have installed all of the packages you need, activate your environment with conda activate my-geopandas-env. See the conda guide to managing environments for more info.

Jupyter/ipython

Some editors/IDEs including jupyter require additional packages - jupyter requires that ipython and ipykernel be installed in order to load the environment within the notebook or editor - that's why I included ipykernel in my list above. See the ipykernel docs for more info.

Other IDES

To link this environment to an IDE such as VSCODE, spider, etc., find the location of this python version with conda run -n my-geopandas-env which python then point your editor to this python executable. Check the docs of your specific editor to get more targeted info about how to set up a conda environment for use with your editor:

Landing answered 15/5, 2022 at 18:25 Comment(3)
I uninstall anaconda and install miniconda, now everything works great and the conda installation is much smaller.Urogenital
This is the best answer and up to date for 2022.Menorrhagia
For Jupyter lab IDE, we need a short instruction to create the geopandas_kernel associates with the environment that has been created for geopandas. The command is similar to this ipython kernel install --name "geopandas_kernel" --user.Menorrhagia
S
7

I don't have conda installed, then using just pip I followed these steps:

Download GDAL and Fiona wheels directly on:

Then:

  1. pip install <gdal.whl>
  2. pip install <fiona.whl>

In my case I did pip install GDAL-3.4.1-cp38-cp38-win_amd64.whl and Fiona-1.8.21-cp38-cp38-win_amd64.whl. Where cp38 stands for python 3.8.

After that you are able to install geopandas with pip as well.

  1. pip install geo pandas
Shiau answered 3/3, 2022 at 13:23 Comment(0)
F
5

For me, the only solution was to install the ready binaries from here

https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal

Then just install locally

pip install GDAL-3.1.4-cp38-cp38-win_amd64.whl

Finstad answered 30/11, 2020 at 23:54 Comment(0)
D
4

One way in which I could install geopandas was through the Anaconda Navigator. Get into the environment and install the package 'geopandas'. After that I could import the geopandas package in spyder

Duquette answered 25/7, 2019 at 23:24 Comment(0)
F
1

I ran into this problem not with anaconda/windows, but with python:3.6 Docker image. Google search always led me to this question, so I think I will share how I resolve my issue in case others also end up here.

Based on here, you need to install system relevant packages in the Dockerfile before running pip install geopandas or pip install requirements.txt:

RUN apt-get update && apt-get install -y --no-install-recommends \
  build-essential \
  libatlas-base-dev \
  libgdal-dev \
  gfortran
Forsythe answered 19/10, 2022 at 19:34 Comment(0)
N
0

I will add

!pip install descartes

to @JDOaktown list.

Nazario answered 19/8, 2020 at 15:46 Comment(2)
That worked in my case. Maybe it helps others as well.Nazario
what is descartes and what didn't work for you to begin with?Ideation
S
0

I started with pip install geopandas and got the error, but later tried with conda install --channel conda-forge geopandas and the error disappeared.

Superpose answered 29/10, 2020 at 16:6 Comment(0)
H
0

Successfully installed in RHEL 7.8. It automatically downloaded the required packages. This might be helpful

Installing collected packages: certifi, pyproj, shapely, attrs, click, click-plugins, munch, cligj, fiona, geopandas Successfully installed attrs-20.3.0 certifi-2020.11.8 click-7.1.2 click-plugins-1.1.1 cligj-0.7.0 fiona-1.8.17 geopandas-0.8.1 munch-2.5.0 pyproj-3.0.0.post1 shapely-1.7.1

Hutton answered 12/11, 2020 at 3:30 Comment(0)
P
0

If you want to install GDAL, Geopandas, Shapely, Fiona etc in a windows Virtual Environment download .whl files for all of them and first install GDAL using pip install gdal-.whl Following this command edit the activate.bat file in you venv\Scripts folder and add GDAL_CONFIG = \venv\Lib\site-packages\osgeo Then you can install rest using pip install

Preserve answered 28/12, 2021 at 19:10 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Brumal
I
0

I started off with a clean environment gdal_test in Conda environments, but made the mistake of using the old activate gdal_test instead of conda activate gdal_test. This made Conda Environment resolving take forever, which is why I resolved to other methods at first.

Takeaway: let conda handle it, with a proper new environment.

Icj answered 17/5, 2022 at 19:3 Comment(0)
R
0

The following worked on macOS:

brew install gdal --HEAD

Verify the installation by running gdal-config --version

Following that pip installation as normal worked without a problem.

Rosettarosette answered 14/12, 2022 at 13:36 Comment(0)
S
0

For Docker users:

RUN apt-get update
RUN apt-get install -y gdal-bin libgdal-dev g++

The above worked for me. Top solutions are misleading since they are suitable only for Windows.

Schuss answered 29/2 at 17:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.