I have troubles to import the basemap module of mpl_toolkits in python. Here is what I get when I run the test.py script from the module directory:
/usr/lib/python2.7/dist-packages/mpl_toolkits/basemap$ python test.py
Traceback (most recent call last):
File "test.py", line 1, in <module>
from mpl_toolkits.basemap import Basemap, shiftgrid
ImportError: No module named basemapI can't get it since sys.path gives a list of paths where I am sure the directory "basemap" is, in the "mpl_toolkits" directory. There is no problem to import mpl_toolkits. Here is a thing I tried, to manually add the path, and the result:
>>> import sys
>>> sys.path.append('/usr/lib/python2.7/dist-packages/mpl_toolkits/basemap')
>>> import basemap
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "basemap/__init__.py", line 30, in <module>
from mpl_toolkits.basemap import pyproj
ImportError: No module named basemapI tried to uninstall an reinstall basemap from source (carefully following these instructions), from apt-get, from conda, but it does not change anything: I can't import basemap.
Thank you for your help
217 Answers
I was in the same situation until a minute ago, installing it through this made the trick:
sudo apt-get install libgeos-3.5.0
sudo apt-get install libgeos-dev
pip install 7 I was facing this issue and I was able to solve it using anaconda
After activating my profile
source activate MyProfileName
conda install basemap
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
# setup Lambert Conformal basemap.
# set resolution=None to skip processing of boundary datasets.
m = Basemap(width=12000000,height=9000000,projection='lcc', resolution=None,lat_1=45.,lat_2=55,lat_0=50,lon_0=-107.)
m.bluemarble()
plt.show() I do not use Anaconda, using MacOS, and I have found this solution works for me. I guess it is straight forward, and should work with both Linux and MacOs.
brew install geos
pip3 install For Ubuntu,
sudo apt-get install geos
sudo pip3 install 1 I had the same issue; trying to access basemap using sys would produce that error. But this worked for me:
import mpl_toolkits
mpl_toolkits.__path__.append('/usr/lib/python2.7/dist-packages/mpl_toolkits/')
from mpl_toolkits.basemap import Basemap 1 Download it from here and install it manually. Make sure to download the right version(i.e. if you are Python3.6 then download basemap‑1.2.0‑cp36‑cp36m‑win_amd64.whl)
Reference:
0For me, a simple
pip3 install basemapdid the trick.
1conda install -c anaconda basemap
OR
Go to Anaconda Navigator, search for basemap and click Apply.
In my Case It works
sudo apt install python3-mpltoolkits.basemap
I followed this answer:
Though, I can have wrongly installed mpl_toolkits (or I do not know), in my case I found out, that basemap is located in pymodules like that:
mpl_toolkits.__path__.append('/usr/lib/pymodules/python2.7/mpl_toolkits/') from mpl_toolkits.basemap import BasemapSo this worked for me on ubuntu 14.04 LTS.
After a day of trying different methods, this worked for me:
conda install -c conda-forge basemap The only solution that worked for windows.
Download wheel package from here: Navigate to download location in terminal. Install using pip install
I was able to get basemap working through the following steps. Note that I did a --user install.
- Create shallow clone of basemap (
git clone --depth 1 :matplotlib/basemap.git) or extract the tarball of the current version. - Install the necessary prerequisite libraries (on Ubuntu,
libgeos-dev,libproj-dev,libgeos++-dev,proj-data,proj-bin,libgeos-c1v5,libgeos,libproj12, I think). pip install --user pyproj matplotlib geos(not actually sure ifgeosis necessary).
Now, here's where I had to improvise a little bit. When I install basemap using python setup.py install, it creates a new egg directory among my Python packages. That directory contains an mpl_toolkits subdirectory which duplicates a separate mpl_toolkits directory installed by matplotlib.
So, instead, I did
python setup.py build_ext --inplace
cp -a lib/mpl_toolkits/basemap /my/python/packages/dir/mpl_toolkits/basemap
cp lib/_geoslib.so /my/python/packages/dirI am now able to run examples like simpletest.py.
I faced the same problem. Couldn't import the Basemap:
from mpl_toolkits.basemap import Basemapbut surprisingly Pycharm saw the library which was apparently installed in this location:
lib/python3.8/site-packages/basemap-1.2.1-py3.8-linux-x86_64.egg/mpl_toolkits/basemap/So, to make it work, I just created a symbolic link in lib/python3.8/site-packages/mpl_toolkits/:
ln -s ../basemap-1.2.1-py3.8-linux-x86_64.egg/mpl_toolkits/basemap/ basemapI know it's not a clean solution, but may be sufficient in some cases.
On Colab you might have to add the basemap module to mpl_toolkits
!pip install basemap
from mpl_toolkits import basemapAt least, I had the same problem and this worked for me.
For Windows:
To install basemap you need to download the wheel file from this path:
for python 3.10 this will be the file:
basemap‑1.3.2‑cp310‑cp310‑win_amd64.whl
Then you have to go to the folder where the above mentioned .whl file is saved and run this command from there:
pip install basemap‑1.3.2‑cp310‑cp310‑win_amd64.whl
For Mac OS please refer:
:
Make sure you have:
brew install geos
brew install matplotlib
brew install numpy
brew install projAdd export GEOS_DIR="/user/local/Cellar/geos/3.10.2/" to your .bash profile and reload it via:
source ~/.bash_profile
git clone --depth 1 then in the basemap/packages/basemap directory
pip3 install
For Colab there are slight variation from Akima's answer since its been a while:
!sudo apt-get install libgeos-3.6.2
!sudo apt-get install libgeos-dev
!pip install git+ If you're using Anaconda, it has a package for basemap
conda install basemap
(pip doesn't have the basemap package any more)
OR
If you using Ubuntu system you can try
apt install python3-mpltoolkits.basemap
I had trouble with that. Fortunately, I solved the problem. Firstly, I suggest you to set Anaconda up, if you don't have. Then follow steps below;
- Create a new environment in anaconda.
- Install Jupyter Notebook and launch it. If it works, turn it off.
- Change your anaconda environment in your terminal.
- Try installation commands below; conda install basemap conda install forge ... pip install basemap