问题
I have problems importing basemap, even though I just installed it via pip install basemap
. I've tried both with python2.7 and python3:
python3
>>> from mpl_toolkits.basemap import Basemap
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'mpl_toolkits'
python2.7
>>> from mpl_toolkits.basemap import Basemap
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.py", line 37, in <module>
import _geoslib
ImportError: libgeos_c.so.1: cannot open shared object file: No such file or directory
I'm on a ubuntu OS.
回答1:
What worked for me on ubuntu:
sudo apt-get install libgeos-3.4.2
sudo apt-get install libgeos-dev
sudo pip install https://github.com/matplotlib/basemap/archive/master.zip
回答2:
It worked for me in python3 with v3.1.2 of matplotlib:
sudo apt-get update -y
sudo apt-get install -y python3-mpltoolkits.basemap
Check matplotlib module version running in python:
>>>import matplotlib
>>>matplotlib.__version__
'3.1.2'
Upgrade module:
sudo pip3 install matplotlib --upgrade
来源:https://stackoverflow.com/questions/29333431/importerror-when-importing-basemap