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:
http://sourceforge.net/projects/matplotlib/files/matplotlib-toolkits/basemap-1.0.1/

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 setup.py install


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

username@my-ubuntu:~Downloads$ python simpletest.py


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!

Cheers!



Added on Oct. 17:

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

ImportError: libgeos-3.2.0.so could not be found by this line: import _geoslib

However, when I tried reinstalling basemap, libgeos-3.2.2.so could be found when running
my-ubuntu$ sudo python setup.py install

So problem was _geoslib.so which somehow was still looking for libgeos-3.2.0.so. I needed to build a new _geoslib.so with the new libgeos-3.2.2.so

The following steps are to cure this:
1. Remove _geoslib.so 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 setup.py install

22 comments:

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...

Hello,
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" .

mm...
E

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.
/Downloads/basemap-1.0.2/src/_geoslib.c
/Downloads/basemap-1.0.2/src/_geoslib.pyx
...
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?
Thanks

plgsekip said...

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

plgsekip@N4030:~$ locate -i geoslib
/home/plgsekip/Downloads/basemap_install/basemap-1.0.1/build/lib.linux-x86_64-2.7/_geoslib.so
/home/plgsekip/Downloads/basemap_install/basemap-1.0.1/build/temp.linux-x86_64-2.7/src/_geoslib.o
/home/plgsekip/Downloads/basemap_install/basemap-1.0.1/src/_geoslib.c
/home/plgsekip/Downloads/basemap_install/basemap-1.0.1/src/_geoslib.pyx
/usr/local/lib/python2.7/dist-packages/_geoslib.so

Eyal said...

Hello,
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
home/plgsekip/Downloads/basemap_install/basemap-1.0.1/build/lib.linux-x86_64-2.7/_geoslib.so
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
...Thanks

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...

hey,
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 :(
help!

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! :)