1

I have trouble importing the basemap module of mpl_toolkits in python. I've got following error message when I try to run "from mpl_toolkits.basemap import Basemap":

ModuleNotFoundError: No module named 'mpl_toolkits.basemap'

I'm using python 3.6.5 in windows.

I've found relevant Q&A in "Python basemap module impossible to import" and I already followed what's instructed there (i.e. source activate MyProfileName, conda install basemap) but it didn't work.

The clue might already be given in the Q&A above but as I'm quite new to python, I couldn't figure out the solution.

yonnie
  • 11
  • 1
  • 1
  • 3
  • SAme issue i had. Used this answer, hope it helps: https://stackoverflow.com/a/50750283/4103997 – Ciaran Nov 11 '18 at 15:12
  • @Ciaran Apologies for the delay in response. I've tried "conda install -c conda-forge basemap" after running python in the Command Prompt, but I still encounter the error: "SyntaxError: invalid syntax". – yonnie Mar 25 '19 at 15:24
  • Does this answer your question? [basemap ImportError: No module named 'mpl\_toolkits.basemap'](https://stackoverflow.com/questions/48388217/basemap-importerror-no-module-named-mpl-toolkits-basemap) – Daraan Jun 28 '23 at 10:25

3 Answers3

1

I would recommend installing Anaconda environment from scratch. Let Anaconda handle dependencies for you. Then you need to install mpl_toolkits separately in your conda environment with:

conda install -c conda-forge basemap-data-hires 

See also here.

After doing this, executing

from mpl_toolkits.basemap import Basemap

from python console should work normally.

mlcr
  • 335
  • 1
  • 7
1

I recently faced this problem on Windows 10. I had created a conda environment with python 3.7 and anaconda 5.2.0 and tried all retrieved solutions. But nothing worked for me and all my efforts worth many hours were in vain.

What I observed that currently Basemap is not compatible with python 3.0, so I remove the environment and creates a fresh with python 2.7 and anaconda 5.2.0. So, to help others who are juggling with same problem, here is the complete set of solution:

Getting the Basemap Toolkit (support the functionality of mapping data)

  1. create conda environment as:

    conda create -n Basemap python=2.7 anaconda=5.2.0 
    
  2. Activate the created conda environment:

    activate Basemap
    
  3. Install the following packages:

    1. conda install -c conda-forge basemap
      

      (do not use basemap=1.1.0, channel error comes "package basemap =1.1.0 is not available from current channels")

      "Only the 'crude' and 'low' resolution datasets are installed by default". You may need to install the following for high resolution:

    2. conda install -c conda-forge basemap-data-hires 
      

      PROJ is a generic coordinate transformation software that transforms geospatial coordinates from one coordinate reference system (CRS) to another. This includes cartographic projections as well as geodetic transformations.

    3. conda install -c conda-forge proj4 </b>
      

      (Better to avoid pro4=5.2.0 as specific packages generates error)

      PROJ is a generic coordinate transformation software that transforms geospatial coordinates from one coordinate reference system (CRS) to another. This includes cartographic projections as well as geodetic transformations.

After installation of the Basemap toolkit, open the jupyter notebook a fresh, it should show the current environment in upper right corner.

To check the current environment in jupyter, type:

import sys
print(sys.executable)

If still the activated environment is not shown then:

  1. run the following command in anaconda prompt in activated environment Basemap:

    python -m ipykernel install --user --name Basemap --display-name "Python (Basemap)"
    
  2. Now change the environment from Kernel-> change kernel -> Python (Basemap)

  3. Finally Python(Basemap) should be shown in upper right corner.

Following needs to be imported in your program then to use it:

from mpl_toolkits.basemap import Basemap

In case of error: "No module named 'mpl_toolkits.basemap" type the following in jupyter:

import os
os.environ['PROJ_LIB'] = r'C:\ProgramData\Anaconda3\pkgs\proj4-5.2.0-h6538335_1006\Library\share  

After this you need to restart apps for them to pick up the change, including explorer.exe. Restarting the machine is reccomended (but not required).

All the best. I hope this will work for you as well.

fcdt
  • 2,371
  • 5
  • 14
  • 26
1

For me this solved the issue on pycharm. Make sure matplotlib is installed and then.

pip install basemap
abdullah
  • 86
  • 1
  • 7