ImportError: No module named geopandas - python

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

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

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.

If using Jupyter notebook with conda use:
conda install -c conda-forge geopandas

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

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.

Related

How install kmapper?

I have installed kmapper since command prompt, but when I import kmapper in jupyter notebook
is visualized a error: No module named kmapper.
What can I do?
I should install kmapper, please help me.
I don't see a Conda version for this in a major Anaconda Cloud channel. Install with pip.
conda create -n my_kmapper_env python pip numpy matplotlib scikit-learn bokeh pillow
conda activate my_kmapper_env
pip install kmapper

ModuleNotFoundError: No module named 'geopandas' [duplicate]

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\
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.
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.
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.
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.
To install gdal, I followed the following steps:
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
Put the file in a folder on the desktop.
From cmd, i moved to that directory and executed python -m pip install GDAL-3.1.4-cp37-cp37m-win_amd64.whl
This is followed by installing fiona the same way: python -m pip install Fiona-1.8.18-cp37-cp37m-win_amd64.whl
For shapely, i executed conda install -c conda-forge shapely
After that, i was able to install keplergl as usual: pip install keplergl
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..
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:
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.
When using conda, you should not mix and match conda channels.
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.
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
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:
Spider: FAQ on using an existing environment and Spider wiki guide to working with packages and environments
VSCode: Using python environments in vscode
PyCharm: Configure a conda virtual environment
I don't have conda installed, then using just pip I followed these steps:
Download GDAL and Fiona wheels directly on:
GDAL: https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal
FIONA: https://www.lfd.uci.edu/~gohlke/pythonlibs/#fiona
Then:
pip install <gdal.whl>
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.
pip install geo pandas
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
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
I will add
!pip install descartes
to #JDOaktown list.
I started with pip install geopandas and got the error, but later tried with conda install --channel conda-forge geopandas and the error disappeared.
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
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
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.
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
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.

How to install Geo Pandas package in Jupyter Notebook in Python ? All solutions do not work

How to install geopandas, I really tried everything and I still has error: ModuleNotFoundError: No module named 'geopandas'. I have the latest version of Python 3.9.6. I use Windows 10, I use Anaconda Prompt, I have only one version of Python.
I do not want to create other environment, I want to install it as any other package, how to do it? I tried:
pip install geopandas
conda install --channel conda-forge geopandas
!conda install geopandas
I checked also this page: https://geopandas.readthedocs.io/en/latest/getting_started/install.html to find solution but I still do not have this package. But package folium was installed correctly by pip install folium.
Help me because I try to do in second day in a row ;/
I will transcribe here the solution I found; all glory goes to Mr. Tanish Gupta, long life to him. Source here :). I hope it helps!
I did this in my win10 PC, I have Anaconda 2.1.4 and only the Python version which comes with it (3.7 I believe). I use Anaconda Prompt, I have only that one version of Python ('cause I had the latest Py ver, but outside Anaconda, and tried this. It worked, but for that 3.10 Python version, not for the Jupyter Py ver, if that makes sense).
To my understanding, probably there is some incompatibility between the libraries installed in the base environment, so we'll be creating a new one.
In the Anaconda command prompt, create a new environment variable:
conda create -n geo_env
Activate this environment “geo_env”, then add and set conda-forge channel:
conda create -n geo_env
conda config --env --add channels conda-forge
conda config --env --set channel_priority strict
Install Geopandas in the environment just created:
conda install geopandas
Next install Jupyter notebook in this environment:
conda install jupyter notebook
Note: If the above command doesn’t work for you, try conda install notebook.
Now add our environment to Jupyter notebook:
python -m ipykernel install --name geo_env
Change to our new environment in the AnacondaNavigator. Enjoy :D
In my case, then I had issues with seaborn and wordcloud in this environment, so I tried installing C++, 'cause it said in the error output, you know, I just wanted more headaches (it didn't work). Finally I installed them in the same way explained before and everything ran smoothly.
If I'm not mistaken you're either having a conflict between channels or you forgot to install geopandas packages when doing it with pip.
First of all, in an anaconda prompt, start by cleaning your environment by removing the packages that got installed by pip.
To do so just pip uninstall geopandas fiona pyproj rtree shapely.
Once you're done with that, run a conda install --channel conda-forge geopandas (normally should work).

Anaconda doesn't import geopandas

How do I make geopandas work? I have a new environment for geopandas. Before that I reinstalled anaconda. Pythom 3.8.5 is included and no other python is installed. When I open jupiter notebook in the specific geo_env with the packages and import geopandsa as gpd it is not working - missing package. I know this topic for geopandas is quite well discussed but I tried all suggestions - different commands "pip"; conda; conda-forge; different versions of the files gdal, diona, shapely etc. (because it's written sometimes 32 bit works on 64 bit - my option).
I work with windows 10/64Bit
I think you can try:
$ conda install -c anaconda pip
$ pip install geopandas
$ pip install Fiona
From Error installing geopandas:" A GDAL API version must be specified " in Anaconda. Your question has been answered well in this thread.
To install gdal, I followed the following steps:
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
Put the file in a folder on the desktop.
From cmd, i moved to that directory and executed python -m pip install GDAL-3.1.4-cp37-cp37m-win_amd64.whl
This is followed by installing fiona the same way: python -m pip install Fiona-1.8.18-cp37-cp37m-win_amd64.whl
For shapely, i executed conda install -c conda-forge shapely
After that, i was able to install keplergl as usual: pip install keplergl
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..

How can I use conda to install pydotplus

I execute the code following on my machine( Win10, python 2.7, Anaconda&Spyder) and meet ImportError: No module named pydotplus .
import networkx as nx
from networkx.drawing.nx_pydot import write_dot
G = nx.DiGraph([(1,2),(2,3),(3,2)])
write_dot(G,'file.dot')
It clearly that I should install pydotplus package. I try to conda install pydotplus directly but says Error: Package missing in current win-64 channels. Then, I google it but find there is no information about how to install it on conda. By the way, I have install pydot on conda before.
Thanks for you help in advance!
Using conda install command below worked for me (globally installed):
conda install -c conda-forge pydotplus
Using Anaconda environments (per environment instance) you can install pydotplus using pip:
pip install pydotplus
I would personally recommend using the Anaconda environments to install your packages for a given solution as its a more modular and cleaner way of building solutions with Anaconda.
Installing via Anaconda environments referenced from answer on Quora, see:
https://www.quora.com/How-do-I-install-Python-packages-in-Anaconda
I tried conda install pydotplus, but it failed.
Then tried python -m pip install pydotplus and it worked.
Try
pip install pydotplus
if it isn't part of the conda universe.
Open Anaconda prompt:
pip install pydotplus

Categories

Resources