How can I install Basemap in Python 3 / Matplotlib 2 on Ubuntu 16.04?
Asked Answered
E

2

12

I tried

pip3 install basemap

but Basemap seems not to be on PyPI.

There is an old question but it has no answer.

What I did

  1. I downloaded basemap 1.07 (source)
  2. Matplotlib 2, numpy 1.11, PIL, python3-dev is installed

I'm not sure where / how to get GEOS (libgeos-dev?). I think I followed the README and it didn't show any errors, but when trying the first line of this

$ python3
>>> from mpl_toolkits.basemap import Basemap

I get

ImportError: libgeos-3.3.3.so: cannot open shared object file: No such file or directory

It is in

$ locate libgeos-3.3.3.so
/home/math/Downloads/basemap-1.0.7/geos-3.3.3/src/.libs/libgeos-3.3.3.so
/usr/local/lib/libgeos-3.3.3.so
Epicedium answered 4/10, 2017 at 8:43 Comment(1)
Isn't the basemap documentation very helpful in saying how to install it?Exhibitionism
S
22

In Ubuntu, this works for me:

$ sudo apt-get install libgeos-dev
$ pip install --user https://github.com/matplotlib/basemap/archive/master.zip

For completeness, if you know you need a specific version, you can find the download links by hovering over the package/version number that you need here. For instance, if I need to install v1.1.0, I can use the above, replacing the second line with:

$ pip install --user https://github.com/matplotlib/basemap/archive/v1.1.0.zip
Sewoll answered 8/1, 2018 at 20:35 Comment(5)
Nice, it worked for me! Just one note: If you are inside a virtual environment, the --user option won't workHithermost
@Hithermost you installed it on python3?Conjurer
@Conjurer yes, did you encounter any problems?Hithermost
For me the last command results in an error during the "Building wheel for basemap (setup.py)" step: src/_geoslib.c:4:10 complains Python.h doesn't exist. Using Python 3.6 on Ubuntu 20.04Maggot
sudo -H apt-get install python.3.6-dev -y solved this issueMaggot
F
2

Try this:

sudo apt-get install libgeos-dev

sudo pip3 install -U git+https://github.com/matplotlib/basemap.git  # latest Version from Source

Older Version might not be compatible with the matplotlib.

Flutist answered 30/4, 2019 at 7:44 Comment(1)
what is the difference between this and the prev answer?Tango

© 2022 - 2024 — McMap. All rights reserved.