开发者社区> 问答> 正文

无法在virtualenv中“将matplotlib.pyplot导入为plt”

我正在虚拟环境中使用烧瓶。我可以通过pip安装matplotlib,并且可以import matplotlib在Python会话中进行安装。但是,当我将其导入为

matplotlib.pyplot as plt

我收到以下错误:

>>> 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.

我对为什么它要求我将Python安装为框架感到困惑。它不存在吗?“将Python作为框架安装”是什么意思,如何安装?

展开
收起
祖安文状元 2020-02-21 17:58:47 801 0
1 条回答
写回答
取消 提交回答
  • 这个解决方案对我有用。如果您已经在虚拟环境中使用pip安装了matplotlib,则只需键入以下内容:

    $ cd ~/.matplotlib
    $ nano matplotlibrc
    
    

    然后backend: TkAgg在那写。如果您需要更多信息,请转到解决方案链接。

    2020-02-21 17:58:54
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载