无法“将 matplotlib.pyplot 导入为 plt";在虚拟环境中 [英] Unable to "import matplotlib.pyplot as plt" in virtualenv
问题描述
我正在虚拟环境中使用烧瓶.我能够使用 pip 安装 matplotlib,并且我可以在 Python 会话中import matplotlib
.但是,当我将其导入为
matplotlib.pyplot 作为 plt
我收到以下错误:
<预><代码>>>>导入 matplotlib.pyplot 作为 plt回溯(最近一次调用最后一次):文件<stdin>",第 1 行,在 <module> 中我很困惑为什么它要求我安装 Python 作为框架.不是已经存在了吗?将 Python 安装为框架"是什么意思,我该如何安装?
这个解决方案 为我工作.如果您已经在虚拟环境中使用 pip 安装了 matplotlib,则只需输入以下内容:
$ cd ~/.matplotlib$ nano matplotlibrc
然后,在其中写入 backend: TkAgg
.如果您需要更多信息,只需转到解决方案链接.
I am working with flask in a virtual environment. I was able to install matplotlib with pip, and I can import matplotlib
in a Python session. However, when I import it as
matplotlib.pyplot as plt
I get the following error:
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "//anaconda/envs/myenv/lib/python2.7/site-packages/matplotlib/pyplot.py", line 109, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "//anaconda/envs/myenv/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "//anaconda/envs/myenv/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 24, in <module>
from matplotlib.backends import _macosx
RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends.
I am confused about why it asks me to install Python as framework. Doesn't it already exists? What does it mean to "install Python as framework", and how do I install it?
This solution worked for me. If you already installed matplotlib using pip on your virtual environment, you can just type the following:
$ cd ~/.matplotlib
$ nano matplotlibrc
And then, write backend: TkAgg
in there.
If you need more information, just go to the solution link.
这篇关于无法“将 matplotlib.pyplot 导入为 plt";在虚拟环境中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!