13

What works is

import mpl_toolkits

What not works is (Import Error basemap not found)

from mpl_toolkits.basemap import Basemap

I followed the instructions here :

http://matplotlib.org/basemap/users/installing.html

Downloaded the lastest basemap*.tar.gz

I run the following commands:

Inside the geos folder

export GEOS_DIR=~/
./configure --prefix=$GEOS_DIR
make
make install

Inside the basemap folder

python setup.py install

Everything runs in sudo mode and no errors. Goes outputs no python binding but not as an error so i am not sure.

It seems not to be properly installed.

Mac Os X 10.10 Yosemite Python 2.7.6

if i type

pip install basemap --allow-external basemap --allow-unverified basemap

Requirement already satisfied (use --upgrade to upgrade): basemap in /Library/Python/2.7/site-packages

so it is there but not importable?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
peter
  • 315
  • 1
  • 3
  • 11
  • did you try re-installing with the `--upgrade` flag? your previous installation might incomplete – Paul H Jan 27 '15 at 16:56
  • 1
    and are you sure that `GEO_DIR` should be your home directory? is that where you want it? (note, with conda this whole process is `conda install basemap` and you're done) – Paul H Jan 27 '15 at 16:57
  • no i have the python shipped with mac os x and want to keep it. the problem is that mpl_toolkits path is ['/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/mpl_toolkits'] but the default installation is /Library/Python/2.7/site-packages how can change this. i don't care where it is as long as it works. – peter Jan 27 '15 at 17:08
  • Using conda doesn't touch Apple's Python – Paul H Jan 27 '15 at 17:09
  • yes but i got a lot of other packages that only work with the default python so i want to keep that. – peter Jan 27 '15 at 17:11
  • That definitely doesn't preclude you from installing the conda package manager into your existing environment. Good luck. – Paul H Jan 27 '15 at 17:12
  • Unfortunately it didn't work for me (10.10.5). This is the error message from port (executed as root): "Error: Port py-matplotlib-basemap not found". It looks like Port can't found the package. Maybe port needs to be configured in some ways? – Lornioiz May 05 '16 at 20:59
  • This question has already been answered here, https://stackoverflow.com/questions/40374441/python-basemap-module-impossible-to-import/55204759#55204759?newreg=f2c0abc758004c7a9ff9134c6fda2720 For Windows specific problem, I believe the only difference is the environmental variables. I would highly suggest using Conda if you can. If you're using Mac, the easiest way to address the problem is by `brew install geos pip install https://github.com/matplotlib/basemap/archive/master.zip` – deirdreamuel Jul 27 '20 at 02:53

4 Answers4

8

What worked for me was this:

brew install gdal

For completeness, I did these things too:

conda install basemap

But this should be similar to your pip install method above.

Also, for completeness, I added this line to my .bash_profile:

export GEOS_DIR=/usr/local/Cellar/geos/3.4.2/

You may need to edit the version number.

Then, you can run:

from mpl_toolkits.basemap import Basemap
scottlittle
  • 18,866
  • 8
  • 51
  • 70
2

The easiest way to install basemap on OS X is to use Ports.

Just type in the below command and the see the magic unfold:

port install  py-matplotlib-basemap
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Linus_30
  • 193
  • 2
  • 14
0

Correct me if I am wrong. Using MacPorts will install a "port" version of python.

If you started off with Anaconda python distribution, the easiest way is:

conda install -c anaconda basemap=1.0.7

Please see the page from Anaconda here

Y.G.
  • 661
  • 7
  • 7
0

The better way is upgrade matplotlib module as follows:

pip3 install matplotlib --upgrade
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
allen yang
  • 95
  • 1
  • 3