无法“将matplotlib.pyplot导入为plt”在virtualenv [英] Unable to "import matplotlib.pyplot as plt" in virtualenv
问题描述
import matplotlib
。但是,当我将它导入为 matplotlib.pyplot为plt
我得到以下错误:
>>> ; import matplotlib.pyplot as plt
Traceback(最近一次调用最后一次):
在< module>中,第1行的文件< stdin>
文件//anaconda/envs/myenv/lib/python2.7/site-packages/matplotlib/pyplot.py,第109行,在< module>
_backend_mod,new_figure_manager,draw_if_interactive,_show = pylab_setup()
文件//anaconda/envs/myenv/lib/python2.7/site-packages/matplotlib/backends/__init__.py,第32行,在pylab_setup
globals(),locals(),[backend_name],0)
文件//anaconda/envs/myenv/lib/python2.7/site-packages/matplotlib/backends/backend_macosx .py,第24行,在< module>
from matplotlib.backends import _macosx
RuntimeError:Python没有安装为框架。如果未将Python作为框架安装,则Mac OS X后端将无法正常运行。有关在Mac OS X上将Python作为框架安装的更多信息,请参阅Python文档。请将Python重新安装为框架,或尝试其他后端之一。
我为什么要求我将Python安装为框架感到困惑。它不存在吗? 将Python作为框架安装意味着什么,以及如何安装它?
解决方案为我工作。如果您已经在您的虚拟环境中使用pip安装了matplotlib,则只需输入以下内容: b $ b $ 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”在virtualenv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!