Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python basemap in google colaboratory

I used to use the following commands to install libgeos and basemap in google colaboratory and it worked perfectly until last week.

!apt-get -qq install libgeos-dev
!pip install -qq https://github.com/matplotlib/basemap/archive/master.zip
from mpl_toolkits.basemap import Basemap, cm

The error shows

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-f27b0fbc3a52> in <module>()
----> 1 from mpl_toolkits.basemap import Basemap, cm
      2 from matplotlib.patches import Polygon

/usr/local/lib/python3.6/dist-packages/mpl_toolkits/basemap/__init__.py in 
<module>()
150 
151 # create dictionary that maps epsg codes to Basemap kwargs.
--> 152 epsgf = open(os.path.join(pyproj.pyproj_datadir,'epsg'))
153 epsg_dict={}
154 for line in epsgf:

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

Is there anyone know how to fix it? Thanks.

like image 416
John Yang Avatar asked Mar 11 '19 16:03

John Yang


People also ask

What is basemap in Python?

Basemap allows you to create map plots in python. It extends matplotlib's functionality by adding geographical projections and some datasets for plotting coast lines and political boundaries, among other things.

How do I import a basemap into a Jupyter notebook?

Go to "Environments" On the Environments Page, select Not Installed from the drop down menu. Search basemap (or any package you want to install) Select and click Apply.


1 Answers

It seems to have something to do with the latest pyproj release (2.0.1), which was released on 10.03.2019. Try installing older version of pyproj, eg. pip install pyproj==1.9.6

like image 116
Chantwaffle Avatar answered Sep 28 '22 09:09

Chantwaffle