How can I avoid PROJ_LIB error in importing basemap?

偶尔善良 提交于 2020-01-13 11:09:14

问题


I tried to import basemap as follows in Python:

from mpl_toolkits.basemap import Basemap

and I get the following error:

Traceback (most recent call last):

  File "<ipython-input-16-880204a64918>", line 2, in <module>
    from mpl_toolkits.basemap import Basemap

  File "C:\Users\bakhadher\AppData\Local\Continuum\anaconda3\lib\site-packages\mpl_toolkits\basemap\__init__.py", line 155, in <module>
    pyproj_datadir = os.environ['PROJ_LIB']

  File "C:\Users\bakhadher\AppData\Local\Continuum\anaconda3\lib\os.py", line 678, in __getitem__
    raise KeyError(key) from None

KeyError: 'PROJ_LIB'

回答1:


From here: https://github.com/conda-forge/basemap-feedstock/issues/30#issuecomment-423512069

import os
import conda

conda_file_dir = conda.__file__
conda_dir = conda_file_dir.split('lib')[0]
proj_lib = os.path.join(os.path.join(conda_dir, 'share'), 'proj')
os.environ["PROJ_LIB"] = proj_lib

from mpl_toolkits.basemap import Basemap```



回答2:


  1. Reintall package(version problem could cause it)
conda install -c conda-forge proj4
conda install basemap
  1. Set enviroment: setenv PROJ_LIB "$CONDA_PREFIX/share/proj"
  2. in python script(need to be custom in different environment)
import os
os.environ['PROJ_LIB'] = '/glade/u/home/lixujin/work/anaconda3/envs/AC_tools/share/proj'



回答3:


I have conda, usually I have this mistake and my solution was:

import os
os.environ['PROJ_LIB'] = '/home/YOUR_USER/anaconda3/share/proj'
from mpl_toolkits.basemap import Basemap
import cartopy.crs as crs


来源:https://stackoverflow.com/questions/54201946/how-can-i-avoid-proj-lib-error-in-importing-basemap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!