问题描述
我正在尝试将底图库安装并导入到我的Jupyter Notebook中,但这会返回以下错误:
I'm trying to install and import the Basemap library into my Jupyter Notebook, but this returns the following error:
KeyError: 'PROJ_LIB'
经过一些在线研究,我了解我要在Anaconda的单独环境中安装Basemap.创建新环境并安装底图(以及所有其他相关库)之后,我已经激活了环境.但是当导入底图时,我仍然收到相同的KeyError.
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.
这是我在MacOS终端中所做的:
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
然后在Jupyter Notebook中运行以下命令:
Then in Jupyter Notebook I run the following:
from mpl_toolkits.basemap import Basemap
谁能告诉我为什么会导致KeyError?
Can anyone tell me why this results in a KeyError?
推荐答案
需要在启动笔记本之前或使用os.environ['PROJ_LIB'] = '<path_to_anaconda>/share/proj'
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'
参考 PyCharm中的底图导入错误-KeyError:'PROJ_LIB'
这篇关于使用Anaconda Jupyter笔记本的底图库-KeyError:PROJ_LIB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!