Importing mpl_toolkits.basemap on Windows?
Asked Answered
E

8

11

I have recently started using Python 3.5 and Anaconda on my Windows pc. I am trying to plot a map. However, When I am in my Jupyter notebook and i type the command

import mpl_toolkits.basemap

I get an error message saying 'no module name' 'mpl_toolkits.basemap' However, I have the module downloaded and in the same C:\Users\Geena file as my .matplotlib, .ipython, .jupyter files, etc.

Anyone know how I can fix this?

Explosive answered 24/1, 2016 at 18:6 Comment(0)
H
10

I've had this issue with anaconda on my windows 7.
I found the way to fix it with python 3.5:
You need to run with administrator rights "Anaconda Prompt" and in "Anaconda Prompt" run following command:

conda install -c conda-forge basemap-data-hires=1.0.8.dev0

, it will show new packages that you need to install and will ask you to install it - say 'Yes'.
After that new packages will be installed and the issue "import mpl_toolkits.basemap" will be fixed.

Thank you.

Hughie answered 31/10, 2016 at 0:20 Comment(0)
F
5

Currently, basemap is not compatible with python 3 for windows users. So, if you try conda install basemap and you have python 3 installed in windows, you'll see a message pointing out that a conflict was found with python 3.

I solved this by installing a python 2.7 environment. Try this: http://conda.pydata.org/docs/py2or3.html

Then you just activate the python 2 environment. For example: activate py27 (py27 is the identifier of my python 2.7 environment).

After that, you can run conda install basemap with no conflict.

Fabrication answered 7/10, 2016 at 19:48 Comment(0)
M
5

I'm using python 3.6.4 on Windows 7 Family Premium (32bit).

Because I was a bit frustrated by the message "no module named 'mpl_toolkits.basemap'", I searched for and tried a dozen of solutions without success : various versions, building from source, problems with VS version, nmake, ... You all know what I mean ;-)

I finally found a quite simple solution that works perfectly well for me :-) Here it is !

  1. from here I downloaded basemap‑1.1.0‑cp36‑cp36m‑win32.whl
  2. I changed the current dir to my download dir
  3. I installed the wheel with python -m pip basemap‑1.1.0‑cp36‑cp36m‑win32.whl
  4. I did the same for matplotlib‑2.2.3‑cp36‑cp36m‑win32.whl

You DO read the versions correctly : matplotlib 2.2.3 and basemap 1.1.0

Everything works fine for me and I finally can plot OSM POI's on a map of Belgium, without any 'trickery' at import :

import requests  # to fetch OSM data
import json  # to get the response

from mpl_toolkits.basemap import Basemap  # ... Belgium is there !
import numpy as np  # for arrays
import matplotlib.pyplot as plt  # to build the populated map

Big big thanks to Christoph Gohlke (Danke Dir Christoph !) who did all the wonderful job !

Micronesia answered 12/8, 2018 at 14:8 Comment(3)
Works on 64 bit Windows 10 too, with basemap‑1.2.0‑cp36‑cp36m‑win_amd64.whlSaritasarkaria
thanks ! works on 64 bit windows 7 with python 3.5.2Meretricious
If someone have issue with step three try python -m pip install basemap‑1.1.0‑cp36‑cp36m‑win32.whlGotland
H
3

When you have Anaconda, you don't download modules anywhere. In your command prompt, you type

conda install basemap

and it is installed with all its dependencies.

Howse answered 9/2, 2016 at 9:3 Comment(5)
Thanks for the info; how is one suppossed to guess such a package name?Repartition
Search anaconda.org/anaconda/repo or, if you are using conda-forge, conda-forge.org/feedstocksHowse
Indeed, thanks :) I'm now facing the fact that package is avail only for python2.7 -- installation in progress!Repartition
@Joël conda-forge has it for all versions anaconda.org/conda-forge/basemap. Generally a good idea to use conda-forge.Howse
Wow, great! I just got basemap for python3.5 with following command: conda install -c conda-forge basemap, and it works like a charm!Repartition
K
2

Anaconda requires an unusual install command for basemap 1.0.7.
https://anaconda.org/anaconda/basemap

To install this package with conda run:
conda install -c https://conda.anaconda.org/anaconda basemap

Kutzer answered 13/4, 2016 at 16:3 Comment(0)
B
1

I just had this issue as well. All you need to do is update matplotlib by doing the following:

pip install --upgrade matplotlib

mpl_toolkits is part of matplotlib and just needs to be updated.

Buyers answered 20/11, 2016 at 2:42 Comment(0)
P
1

If you're using anaconda, the easiest thing to do is described here: in the conda prompt (as admin), type conda install -c anaconda basemap.

Pinnate answered 29/8, 2018 at 11:28 Comment(0)
H
0

For people of the future : "Basemap is deprecated in favor of the Cartopy project." https://matplotlib.org/basemap/users/intro.html#cartopy-new-management-and-eol-announcement

Hushaby answered 6/1, 2021 at 21:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.