问题描述
我正在尝试安装 Basemap 库并将其导入我的 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.创建新环境并安装 Basemap(以及所有其他相关库)后,我已激活该环境.但是在导入 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?
推荐答案
需要在启动 notebook 之前或在 python 中使用 os.environ['PROJ_LIB'] = '<path_to_anaconda> 设置 PROJ_LIB 环境变量./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 Notebooks 的底图库 - KeyError: PROJ_LIB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!