Saturday, October 15, 2011

Installing Matplotlib Basemap 1.0.1 on Ubuntu 11.04 64bit

Recently I've spent much of my time trying to plot a map and visualizing data resulted from my simulation program. After reading here and there I found basemap and matplotlib to be the most suitable choice in my opinion. This short tutorial is posted as a personal note which might be useful in the future, in case I need to reinstall basemap on my PC.

1. Using Synaptic Package Manager, do install python 2.7.1, numpy 1.5.1, python-matplotlib 0.99.3, libgeos-dev 3.2.0-1, shapelib 1.2.10-5, python-imaging 1.1.7-2build2 and all of their respective dependencies.

2. Download the basemap-1.0.1.tar.gz from here:

3. Using Archive Manager, extract the file: basemap-1.0.1.tar.gz

4. Run the following commands:
username@my-ubuntu:~Downloads$ cd basemap-1.0.1/

username@my-ubuntu:~Downloads$ python install

5. Check the installation:
username@my-ubuntu:~Downloads$ cd examples/

username@my-ubuntu:~Downloads$ python

If it displays a map on the screen, then all is set. This works for me, so I hope this will also work for you!


Added on Oct. 17:

I just got my Ubuntu 11.10 upgrade and suddenly basemap error occurs. It could not find which was understandable because Ubuntu upgrade remove this "old package" of and install the new

ImportError: could not be found by this line: import _geoslib

However, when I tried reinstalling basemap, could be found when running
my-ubuntu$ sudo python install

So problem was which somehow was still looking for I needed to build a new with the new

The following steps are to cure this:
1. Remove in /usr/local/lib/python2.7/dist-packages/
2. Change directory to /basemap-1.0.1/build/
3. Remove this folder --> lib.linux-x86_64-2.7/
4. Reinstall basemap-1.0.1 by running sudo python install


joe said...

Thanks for posting this. I was running into problems with Basemap as well after upgrading to 11.10!

plgsekip said...

You're welcome. Thanks for visiting. Cheers!

Eyal said...

I ran to the problem above, but I can not find _geoslib in/usr/local/lib/python2.7/dist-packages/ but I do have libgeos-3.2.2 installed..

Any ideas?

plgsekip said...

Hi Eyal!
I think _geoslib should be in your python installation path under the dist-packages. If you have confirmed of the libgeos-3.2.2 installation, then I am sure if you can reinstall the basemap by performing the steps I mentioned, it'll be alright. The problem is, you really have to remove the "old" _geoslib... Can you LOCATE it by typing "sudo locate geoslib"? Or you can also use any other file finding tool in Linux.

Eyal said...
This comment has been removed by the author.
Eyal said...

Hello plgsekip
I looked in dist-pacages, and have tried different search methods including "sudo locate geoslib" .


April 5, 2012 7:15 AM

plgsekip said...

Hi Eyal!
Perhaps you need to update your locate database by typing "sudo updatedb". And also you may be interested in typing "sudo locate -i \geoslib" or "locate -i geoslib". Just a thought. Thanks.

Eyal said...

ok so apparently it ia in my download.
So I guess I do should not delete it in this case...

Eyal said...

Mm still stuck on that...

Eyal said...

Hello plgsekip,
So apparently geoslib was found only in the download..what do you suggest at this point?

plgsekip said...

Hi Eyal!
This is my locate result. I do not know why you do not have the "" in you python dist-packages path like I have.

plgsekip@N4030:~$ locate -i geoslib

Eyal said...

First I was wondering what is "python-imaging 1.1.7-2build2", that is listed above to be installed?

Second, the fact that you have in the path
vasemap_install and build is because you have installed the repository?

My CPU is 32 not 64 could that be the problem?

plgsekip said...

Hi Eyal.
I wonder if you have installed libgeos-dev.

Eyal said...
This comment has been removed by the author.
Eyal said...

Yap I just installed it yesterday that was missing..

But only with your suggestion I went a head and tried to install the Basemap 1.0.2....................worked

plgsekip said...

Hi Eyal!
Glad to hear that. You are most welcome. Cheers!

Chaitra20031990 said...
This comment has been removed by the author.
Chaitra20031990 said...

these are the errors that i encountered.

src/_geoslib.c:224:20: fatal error: geos_c.h: No such file or directory
compilation terminated.
src/_geoslib.c:224:20: fatal error: geos_c.h: No such file or directory
compilation terminated.
error: Command "gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/share/pyshared/django/contrib/gis/geos/include -I/usr/lib/pymodules/python2.7/numpy/core/include -I/usr/lib/pymodules/python2.7/numpy/core/include -I/usr/include/python2.7 -c src/_geoslib.c -o build/temp.linux-i686-2.7/src/_geoslib.o" failed with exit status 1

i couldn't find geoslib in /usr/local/bin/python/dist-packages. it is present only in basemap1.0.1 folder. i also deleted the folder from basemap1.0.1/build. it still doesn't work :(

Chaitra20031990 said...

okay, i figured it out! :D
thought it'd be helpful if i posted it here.
so, if the above mentioned commands doesn't get basemaps running, type the following command in terminal

apt-get install python-matplotlib python-numpy libgeos-dev python-httplib2 python-imaging

and then, re-install basemaps. it works! :)

plgsekip said...

Hi Chaitra20031990!
Have you installed libgeos-dev on your system? Thanks.

plgsekip said...

Hi Chaitra20031990
Glad to hear that. :-D
Wow, the comments were almost at the same time. Cheers!

Chaitra20031990 said...

yes :D thanks a ton! :)