Basemap library using Anaconda Jupyter Notebooks – KeyError: PROJ_LIB

anacondajupyter-notebookmatplotlib-basemap

I'm trying to install and import the Basemap library into my Jupyter Notebook, but this returns the following error:

KeyError: 'PROJ_LIB'

After some research online, I understand I'm to install Basemap on a separate environment in Anaconda. After creating a new environment and installing Basemap (as well as all other relevant libraries), I have activated the environment. But when importing Basemap I still receive the same KeyError.

Here's what I did in my MacOS terminal:

conda create --name Py3.6 python=3.6 basemap
source activate Py3.6
conda upgrade proj4
env | grep -i proj
conda update --channel conda-forge proj4

Then in Jupyter Notebook I run the following:

from mpl_toolkits.basemap import Basemap

Can anyone tell me why this results in a KeyError?

Best Answer

Need to set the PROJ_LIB environment variable either before starting your notebook or in python with os.environ['PROJ_LIB'] = '<path_to_anaconda>/share/proj'

Ref. Basemap import error in PyCharm —— KeyError: 'PROJ_LIB'

Related Topic