basemap: KeyError 'PROJ_LIB'
I install basemap
with the command
conda install basemap -c conda-forge
but
from mpl_toolkits.basemap import Basemap
returns:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-23-212c45f90d40> in <module>()
----> 1 from mpl_toolkits.basemap import Basemap
2 #import matplotlib.pyplot as plt
3 import numpy as np
/srv/conda/lib/python3.6/site-packages/mpl_toolkits/basemap/__init__.py in <module>()
144
145 # create dictionary that maps epsg codes to Basemap kwargs.
--> 146 pyproj_datadir = os.environ['PROJ_LIB']
147 epsgf = open(os.path.join(pyproj_datadir,'epsg'))
148 epsg_dict={}
/srv/conda/lib/python3.6/os.py in __getitem__(self, key)
667 except KeyError:
668 # raise KeyError with the original key value
--> 669 raise KeyError(key) from None
670 return self.decodevalue(value)
671
KeyError: 'PROJ_LIB'
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 32 (13 by maintainers)
I can confirm this behavior with a clean install of basemap via conda into a new environment. You can see in the traceback that it refers to a conda environment:
PROJ_LIB
does not appear anywhere in Basemap. This is a downstream change in the conda-forge package that should be discussed there. So I’m closing this issue since it is not Basemap related.It seems the environment variable PROJ_LIB is not being set in the environment.
For python/ipython in a terminal, I managed to rectify by updating proj4:
However, the problem persisted inside Jupyter. I think they may have fixed it recently. I haven’t been able to test that pull yet.
In the meantime, a quick workaround (in your Jupyter kernel), for me at least, was to add the variable explicitly in my kernel.json file:
Nonetheless, I’m not sure if the assumption of the presence of the environment variable in
basemap/__init__.py
:should be there. It didn’t appear to be in the previous version (1.0.7).
Are you installing it on your root environment? If so the env vars won’t be activate, you must install it in an env:
PS: this is not an issue with
basemap
but actually how conda packages work.this was the only way to resolve the KeyError ‘PROJ_LIB’, using this : https://gist.github.com/junzis/36fee36acd7cadfdf1c01c06d97f4947