1

I'm using Windows 10, anaconda navigator, and jupyter notebook 5.7.4 throws an error when I try to import 'basemap' using "from mpl_toolkits.basemap import basemap"

I'm very new to python. Following a tutorial to learn GIS mapping with python, I've installed all the required packages: pandas, numpy, geopandas, basemap, matplotlib, pillow and a few others.

The tutorial code says to write "from mpl_toolkits.basemap import basemap" However, mpl_toolkits does not appear to be an available package when I search for it in the anaconda navigator or in the anaconda prompt.

Having searched the anaconda user guide and the matplotlib web page, I am inferring that mpl_toolkits is included within matploblib?

The error that results is this: ImportError: cannot import name 'basemap' from 'mpl_toolkits.basemap' (C:\Users\Kevin\AppData\Local\conda\conda\envs\mapping\lib\site-packages\mpl_toolkits\basemap__init__.py)

# command to display matplotlib plots inline within the ipython notebook
%matplotlib inline

# import necessary modules
import numpy as np, matplotlib.pyplot as plt, pandas as pd, geopandas as 
gpd
from mpl_toolkits.basemap import basemap
from shapely.geometry import Point
from geopy.distance import great_circle

I expect the jupyter notebook to load all of the modules but instead I get the above error.

Any help is much appreciated, this is my first go at something like this so I am probably making a simple neophyte mistake.

KevinD
  • 11
  • 3
  • You might be either using a different version of mpl_toolkits or Jupyter notebook is using a different interpreter than anaconda. Try this `import sys` and then `print(sys.executable)` to see the path to the python interpreter. It might use one that is not anaconda so you have to either change the interpreter or install it in environment where the interpreter is. – k88 Jan 02 '19 at 01:49
  • Thank you for replying @k88 -- when I type in those commands in the anaconda prompt it outputs the following. Does that make sense to you? (base) C:\Users\Kevin>activate mapping (mapping) C:\Users\Kevin>import sys 'import' is not recognized as an internal or external command, operable program or batch file. (mapping) C:\Users\Kevin>conda import sys CommandNotFoundError: No command 'conda import'. (mapping) C:\Users\Kevin>print(sys.executable) Unable to initialize device PRN (mapping) C:\Users\Kevin> – KevinD Jan 02 '19 at 02:00
  • It seems that you have two environments, one which is `base` and the other is `mapping`. The following error says it cannot find the `sys` cmmand which is rather peculiar as it seems that there is no python interpreter associated with that enviroment. Can you type in the following command in a terminal? `conda env list`, you should see the different environments. You can then activate an environment by typing `conda activate `, launch python by typing in `python` and try importing the mpl_library. See if that works ? – k88 Jan 02 '19 at 02:10

1 Answers1

0

Seems this is very peculiar to Anaconda. If you correctly installed all the dependencies you should check this Python basemap module impossible to import

Silas Jojo
  • 41
  • 3