ImportError when importing Basemap

馋奶兔 提交于 2019-12-10 15:43:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!