Unable to import Python base module

I am having problems importing the base module mpl_toolkits in python. This is what I get when I run 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 not get it, since sys.path gives a list of paths in which I am sure that the baseemap directory is in the mpl_toolkits directory. There import mpl_toolkits no problems for import mpl_toolkits . Here is what I tried to manually add the path and 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 remove the basemap reinstallation from the source (carefully following these instructions), from apt-get, from conda, but this doesnโ€™t change anything: I canโ€™t import the basemap.

thanks for the help

+13
source share
7 answers

I ran into this problem 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 Base Card Format

+13
source

I was in the same situation until a minute ago, installing it, this did the trick:

 sudo apt-get install libgeos-3.5.0 sudo apt-get install libgeos-dev sudo pip install https://github.com/matplotlib/basemap/archive/master.zip 
+15
source

I had the same problem; attempting to access the base map using sys will result in this error. But it worked for me:

 import mpl_toolkits mpl_toolkits.__path__.append('/usr/lib/python2.7/dist-packages/mpl_toolkits/') from mpl_toolkits.basemap import Basemap 
+6
source

I was able to configure the basemap by following these steps. Please note that I installed --user .

  1. Create a surface clone of the base git clone --depth 1 git@github.com :matplotlib/basemap.git ( git clone --depth 1 git@github.com :matplotlib/basemap.git ) or extract the archive of the current version.
  2. Install all the necessary libraries (on Ubuntu, libgeos-dev , libproj-dev , libgeos++-dev , proj-data , proj-bin , libgeos-c1v5 , libgeos , libproj12 , I think).
  3. pip install --user pyproj matplotlib geos (not really sure if geos is geos ).

Now here, where I had to improvise a bit. When I install the basemap using python setup.py install , it creates a new egg directory among my Python packages. This directory contains the mpl_toolkits subdirectory which duplicates the 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/dir 

Now I can run examples like simpletest.py .

0
source

I followed this answer:

fooobar.com/questions/1259142 / ...

Although I can set mpl_toolkits incorrectly (or I donโ€™t know), in my case I found that the base card is located in such pimodules:

  mpl_toolkits.__path__.append('/usr/lib/pymodules/python2.7/mpl_toolkits/') from mpl_toolkits.basemap import Basemap 

So this works for me on Ubuntu 14.04 LTS.

0
source

Download it from here and install it manually. Make sure you download the correct version (that is, if you are Python3.6, then download basemap - 1.2.0 - cp36 - cp36m - win_amd64.whl )

Link: fooobar.com/questions/995448 / ...

0
source

You may also need to install setuptools. This allows mpl_toolkits to be a namespace package that can span multiple directories (i.e. both matplotlib and baseemap).

-1
source

Source: https://habr.com/ru/post/1259142/


All Articles