Basemap import error in PyCharm — KeyError: #39;PROJ_LIB#39;(PyCharm 中的底图导入错误 — KeyError: PROJ_LIB)
问题描述
我尝试使用 Basemap 包通过 PyCharm 绘制地图,但我遇到了问题
I tried to use Basemap package to plot a map by PyCharm, but I got something wrong with
from mpl_toolkits.basemap import Basemap`
回溯如下:
Traceback (most recent call last):
File "/Users/yupeipei/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2963, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-4-0a24a3a77efd>", line 7, in <module>
from mpl_toolkits.basemap import Basemap
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 20, in do_import
module = self._system_import(name, *args, **kwargs)
File "/Users/yupeipei/anaconda3/lib/python3.6/site-packages/mpl_toolkits/basemap/__init__.py", line 146, in <module>
pyproj_datadir = os.environ['PROJ_LIB']
File "/Users/yupeipei/anaconda3/lib/python3.6/os.py", line 669, in __ getitem__
raise KeyError(key) from None
KeyError: 'PROJ_LIB'
我对 PyCharm 上的这个错误感到困惑,因为相同的脚本在 Jupyter 或 Spyder 上运行正确!PyCharm 中的环境是 ../anaconda3/lib/python3.6,与 anaconda 相同.
I'm confused with this error on PyCharm, because the same script is running correctly on Jupyter or Spyder! The environment in PyCharm is ../anaconda3/lib/python3.6 where is same from anaconda.
以前有人遇到过这个错误吗?
Has anyone met this error before?
谁能帮我解决这个错误?
Could anyone can help me to solve this error?
推荐答案
对于带有 Anaconda + Python 3.71 的 Windows 10(我相信其他 Python 3 版本和 Windows 7/8),您可以告诉 Basemap Proj4 的epsg"在哪里"文件是成功的.我没有环境"或其他任何东西,因为要弄清楚的工作量太大 - 所以我没有 anacondashareproj 区域(据我所知,为什么我没有它).
For Windows 10 with Anaconda + Python 3.71 (and I'm sure other Python 3 versions and Windows 7/8), you can tell Basemap where Proj4's "epsg" file is to succeed. I don't have an "environment" or whatever because it's too much work to figure out - so I didn't have an anacondashareproj area (as far as I could discern why I didn't have it).
但是,Basemap 需要的是文件epsg",请使用 Windows 资源管理器在 Anaconda 目录中搜索它.如果找不到,请打开Anaconda Prompt"并输入以下内容来安装 Proj4:
But, what Basemap wants is the file "epsg", search the Anaconda directory for it with Windows Explorer. If it doesn't find it, install Proj4 by opening the "Anaconda Prompt" and typing in:
conda install -c conda-forge proj4
如果找到它,它应该是这样的:
If it finds it, it should be in something like:
C:UtilitiesPythonAnacondaLibraryShare (这是我的位置,以及我猜它放置包本身的 pkgs 地方 - 如果这些也可以工作需要,我一开始使用它们,但库应该更好地通过更新(也许).
C:UtilitiesPythonAnacondaLibraryShare (it's where mine was, as well as pkgs places where I guess it puts the package itself - and those can work too if need be, I used them at first, but the library one should work through updates better (maybe)).
在导入底图之前使用以下代码,它会起作用.将环境变量 PROJ_LIB 设置为 epsg 所在的任何位置,然后 Basemap 即可.
Use the following code before importing Basemap and it'll work. Sets the environment variable PROJ_LIB to wherever epsg is and then Basemap can be happy.
import os
os.environ["PROJ_LIB"] = "C:\Utilities\Python\Anaconda\Library\share"; #fixr
from mpl_toolkits.basemap import Basemap
作为一个不错的奖励,要获取 Basemap 的高分辨率数据(Anaconda 不包含在 Basemap 安装开始),请输入Anaconda Prompt":
As a nice bonus, to get hi-res data of Basemap, which Anaconda doesn't include in the Basemap install to start, type into "Anaconda Prompt":
conda install -c conda-forge basemap-data-hires
这篇关于PyCharm 中的底图导入错误 — KeyError: 'PROJ_LIB'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PyCharm 中的底图导入错误 — KeyError: 'PROJ_LIB&
基础教程推荐
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
