10

I just ran this code and got this error, I'm not sure why:

%matplotlib inline
​
import seaborn as sns
import pandas as pd
import pysal as ps
import geopandas as gpd
import numpy as np
import matplotlib.pyplot as pet

ImportError: No module named geopandas

Haldean Brown
  • 12,411
  • 5
  • 43
  • 58
Fan Wu
  • 159
  • 1
  • 2
  • 6
  • 2
    Is geopandas installed? Try pip install geopandas (you will also need geos_c library installed on your OS for this) – kiliantics Dec 07 '16 at 04:22
  • I am having the same issue. pip failed with fiona. So tried conda and then conda-forge. Still ending up with: ModuleNotFoundError: No module named 'geopandas' – kosmos Aug 10 '20 at 23:21
  • 1
    Same here. geopandas *is* installed in my Anaconda environment. it shows up in the list in the Anaconda Navigator. Also, in the Anaconda prompt, with the environment activated, when giving the command *conda list*, it turns up in the list. Still, in Spyder but also when just starting Python from the command prompt, *import geopandas* results in that error. I've tried the ipython solution (see other answer) but ipython is already included in the envuironment. – Reinier May 10 '21 at 13:25

5 Answers5

17

Check if geopandas is installed

>>> import sys
>>> 'geopandas' in sys.modules
False                            => Not Installed
>>> 

To install the released version, you can use pip:

pip install geopandas

or you can install the conda package from the conda-forge channel:

conda install -c conda-forge geopandas

You may install the latest development version by cloning the GitHub repository and using the setup script:

git clone https://github.com/geopandas/geopandas.git
cd geopandas
pip install .

It is also possible to install the latest development version directly from the GitHub repository with:

pip install git+git://github.com/geopandas/geopandas.git

Linux?

sudo apt-get install python-geopandas
sinhayash
  • 2,693
  • 4
  • 19
  • 51
  • Any idea why after installing pip3 install geopandas under the conda virtual env returns false when invoking ''geopandas' in sys.modules'? If I do 'conda install -c conda-forge geopandas' it returns true... – zcahfg2 Jan 31 '19 at 15:03
  • I tried both 'conda install -c conda-forge geopandas' and 'Conda install geopandas' under virtual env and still get False and no module found error, any idea? – Mojgan Mazouchi Jun 08 '19 at 21:28
  • 1
    Your answer does not address the question. The OP has already tried installing it successfully and still not succeeding in getting it to work – kosmos Aug 10 '20 at 23:22
8

You might encounter this problem even if geopandas is correctly installed in your active environment. Your problem might be related to ipython not being installed in the environment you installed geopandas in. In this case ipython from outside of the environment is used and will find no module named geopandas resulting in a ImportError.

Assuming a Linux OS:

  • You can check which ipython is used with where ipython.
  • You can install ìpython in your active environment by executing conda install ipython.
marianoju
  • 334
  • 4
  • 15
2

If using Jupyter notebook with conda use:

conda install -c conda-forge geopandas
David Buck
  • 3,752
  • 35
  • 31
  • 35
Tanmesh Shah
  • 67
  • 1
  • 3
  • That worked for me when I entered `conda install -c conda-forge geopandas` from within a notebook, but it didn't work when I tried from within bash. – Patty Jula Mar 11 '20 at 15:38
1

If you have any trouble installing GeoPandas, just follow the below steps:

⦁ Go to Unofficial Windows Binaries for Python Extension Packages. (https://www.lfd.uci.edu/~gohlke/pythonlibs/)

⦁ Download the following binaries in a specifi folder in your laptop/PC:

GDAL,

Pyproj,

Fiona,

Shapely &

Geopandas

matching the version of Python, and whether the 32-bit or 64-bit OS is installed on your laptop. (E.g. for Python v3.8x (64-bit), GDAL package should be GDAL-3.3.2-cp38-cp38-win_amd64.whl)

Go to the folder where the binaries are downloaded in the command prompt window. (C:\Users\abc\GeoPandas dependencies) Order of execution of the following commands matter.

pip install .\GDAL-3.3.2-cp38-cp38-win_amd64.whl

pip install .\pyproj-3.2.0-cp38-cp38-win_amd64.whl

pip install .\Fiona-1.8.20-cp38-cp38-win_amd64.whl

pip install .\Shapely-1.7.1-cp38-cp38-win_amd64.whl

pip install .\geopandas-0.9.0-py3-none-any.whl

Credit

mpriya
  • 823
  • 8
  • 15
-1

As mentioned by @marianoju, the problem is likely because you do not have IPython installed in your current environment.

The simple solution is to install IPython in your current environment.

conda install ipython

An even better solution (in my opinion) is to install Jupyter notebook, Jupyter lab in your new conda environment.

conda install jupyter

conda install jupyterlab

This will install jupyter(lab) along with its all dependencies (and that includes IPython). So, any other lurking dependency issues would have been solved in one command.

GeoAfrikana
  • 45
  • 1
  • 3