Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python basemap module impossible to import

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 

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 

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.

Thank you for your help

like image 215
Arnaud BUBBLE Avatar asked Nov 02 '16 07:11

Arnaud BUBBLE


People also ask

Is basemap still available?

Basemap is deprecated in favor of the Cartopy project. See notes in Cartopy, New Management, and EoL Announcement for more details.


2 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 https://github.com/matplotlib/basemap/archive/master.zip 
like image 50
Akima Avatar answered Oct 01 '22 01:10

Akima


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() 

BlueMarble format of basemap

like image 35
Anant Gupta Avatar answered Oct 01 '22 01:10

Anant Gupta