问题描述
我在用python导入mpl_toolkits的底图模块时遇到麻烦.这是从模块目录运行test.py脚本时得到的:
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 basemap
我无法获得它,因为sys.path
在"mpl_toolkits"目录中提供了我确定目录"basemap"所在的路径列表. import mpl_toolkits
没有问题.这是我尝试手动添加路径和结果的方法:
I 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 basemap
我尝试从源代码中卸载重新安装底图(请认真遵循这些指令),从apt-get,从conda,但它并没有改变任何东西:我无法导入底图.
I 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.
谢谢您的帮助
推荐答案
我遇到了这个问题,我能够使用anaconda来解决它
I was facing this issue and I was able to solve it using anaconda
激活我的个人资料后
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()
这篇关于Python底图模块无法导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!