Installing basemap on Mac / Python
Asked Answered
F

6

24

I'm having trouble to get the basemap to work in Python in my Mac.

I keep receiving:

    from mpl_toolkits.basemap import basemap
ImportError: No module named basemap

What I did:

brew install gdal
brew install gets
export GEOS_DIR=/usr/local/Cellar/geos/3.4.2/
basemap-1.0.7 $ python setup.py install

I also tried:

basemap-1.0.7 $ cd geos-3.3.3
basemap-1.0.7/geos-3.3.3 $ export GEOS_DIR=~/
basemap-1.0.7/geos-3.3.3 $ ./configure --prefix=$GEOS_DIR
basemap-1.0.7/geos-3.3.3 $ make
basemap-1.0.7/geos-3.3.3 $ make install
basemap-1.0.7/geos-3.3.3 $ cd ..
basemap-1.0.7 $ python setup.py install

None of them worked for me. How can I get this package to work on a MacOS Sierra?

Fluffy answered 17/2, 2017 at 13:36 Comment(0)
A
23

Did you ever manage to get it working?

I was able to install Basemap fine on Sierra (also using Homebrew for its dependencies), following the instructions here: http://matplotlib.org/basemap/users/installing.html

A couple notes, just to make sure nothing is being overlooked:

  • In your notes, you listed brew install gets, though I assume it was a typo and you actually meant & used brew install geos when installing.
  • Are you certain the correct version of geos was used when modifying your .bash_profile? Some of the examples I've seen around the web use a specific version, so there's always a chance for a copy/paste error. As of yesterday, the version I wound up using was 3.5.0, so my path looked like this: export GEOS_DIR=/usr/local/Cellar/geos/3.5.0/. The version can be verified by looking in your /usr/local/Cellar/geos/ directory to see which one is installed.
  • I'm not 100% certain this matters, but did you reload your .bash_profile after modifying it? source ~/.bash_profile.

This is a full list of what I did:

brew install matplotlib
brew install numpy
brew install geos
brew install proj

Downloaded Basemap 1.0.7 source tar file (https://sourceforge.net/projects/matplotlib/files/matplotlib-toolkits/), untarred it.

Added export GEOS_DIR=/usr/local/Cellar/geos/3.5.0/ to a new line in my .bash_profile, and then reloaded it via:

source ~/.bash_profile

From within untarred Basemap directory:

python setup.py install

Imported Basemap in a python script (via a tutorial elsewhere) with import mpl_toolkits.basemap as bm, and was able to confirm it worked with a produced map.

Athalla answered 26/4, 2017 at 17:51 Comment(4)
Thank you, @TimKlimowicz. I did not reload the bash profile. I'll follow your guide and give you a feedback, thank you. (:Fluffy
The installation guide now links to basemap releases here: github.com/matplotlib/basemap/releasesNiblick
I also had to run sudo python setup.py installNiblick
getting errors after python setup.py install ```Chlorite
F
28

On 10.14 Mojave today I did:

brew install geos
pip3 install https://github.com/matplotlib/basemap/archive/master.zip

and it seems to work (mine is Python 3.6 from https://python.org with matplotlib installed by pip).

Fitzwater answered 6/11, 2018 at 12:15 Comment(2)
I think this one is the simplest answer I found!Marmolada
This is what I have been searching for. ThanksYe
A
23

Did you ever manage to get it working?

I was able to install Basemap fine on Sierra (also using Homebrew for its dependencies), following the instructions here: http://matplotlib.org/basemap/users/installing.html

A couple notes, just to make sure nothing is being overlooked:

  • In your notes, you listed brew install gets, though I assume it was a typo and you actually meant & used brew install geos when installing.
  • Are you certain the correct version of geos was used when modifying your .bash_profile? Some of the examples I've seen around the web use a specific version, so there's always a chance for a copy/paste error. As of yesterday, the version I wound up using was 3.5.0, so my path looked like this: export GEOS_DIR=/usr/local/Cellar/geos/3.5.0/. The version can be verified by looking in your /usr/local/Cellar/geos/ directory to see which one is installed.
  • I'm not 100% certain this matters, but did you reload your .bash_profile after modifying it? source ~/.bash_profile.

This is a full list of what I did:

brew install matplotlib
brew install numpy
brew install geos
brew install proj

Downloaded Basemap 1.0.7 source tar file (https://sourceforge.net/projects/matplotlib/files/matplotlib-toolkits/), untarred it.

Added export GEOS_DIR=/usr/local/Cellar/geos/3.5.0/ to a new line in my .bash_profile, and then reloaded it via:

source ~/.bash_profile

From within untarred Basemap directory:

python setup.py install

Imported Basemap in a python script (via a tutorial elsewhere) with import mpl_toolkits.basemap as bm, and was able to confirm it worked with a produced map.

Athalla answered 26/4, 2017 at 17:51 Comment(4)
Thank you, @TimKlimowicz. I did not reload the bash profile. I'll follow your guide and give you a feedback, thank you. (:Fluffy
The installation guide now links to basemap releases here: github.com/matplotlib/basemap/releasesNiblick
I also had to run sudo python setup.py installNiblick
getting errors after python setup.py install ```Chlorite
A
3

I had trouble installing Basemap on macOS Catalina. Got all the dependencies installed but Basemap itself was giving me trouble.

I wound up needing to install with

$ pip3 install /path/to/basemap.tar.gz --user

after downloading the latest release archive from the releases page.

Not sure if it’ll help anyone else, but after an hour of flailing and trying different things, it got me up and running where trying to install from GitHub (which would build, but not install, a wheel for Basemap) and directly compiling wouldn’t.

Ats answered 24/8, 2019 at 3:37 Comment(2)
Thank you!! Tried so many things, this worked. Am on MacOS 11.4. Exact sequence: brew install geos, export GEOS_DIR="/usr/local/Cellar/geos/3.10.2/" (and added to .bash_profile), git clone --depth 1 https://github.com/matplotlib/basemap.git, then in the basemap/packages/basemap directory pip3 install .Canine
Heh, this wound up breaking for me and out of frustration I conceded defeat and migrated to cartopy. Glad my answer was still able to point you in the right direction.Ats
M
2

After trying for a long time I managed to make basemap-1.1.0 install on High Sierra. Dependency versioning was important.

I installed Python 3.6 with homebrew. Next I created a venv. I then used pip to install matplotlib pip install matplotlib==2.2 (3+ wouldn't work).

I then followed the instructions here:

https://www.fsanmartin.co/mac-install-matplotlib-basemap-on-virtualenv/

And it finally worked!

Big thank you to the kind person who wrote those instructions.

Mize answered 26/10, 2018 at 8:46 Comment(0)
H
1

Thought someone might find this handy since I needed hours to get basemap working.

I'm using High Sierra with Python 2.7 installed with homebrew. Followed what thegsi had said, but then I still had this error

AttributeError: 'module' object has no attribute 'pyproj_datadir'

Turned out I need to use an earlier version of pyproj, so I simply ran

pip install pyproj==1.9.6

and then run one of the examples scripts on the basemap folder, and voilà the basemap works!!!

Huysmans answered 18/10, 2019 at 20:56 Comment(0)
W
1

I had trouble with that. Fortunately, I solved the problem. Firstly, I suggest you to set Anaconda up, if you don't have. Then follow below steps;

  • Create a new environment in anaconda.
  • Install Jupyter Notebook and launch it. If it works, turn it off.
  • Change your anaconda environment in your terminal.
  • Try installation commands below; conda install basemap conda install forge ... pip install basemap
Waken answered 13/4, 2022 at 12:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.