【问题标题】:Pipenv install matplotlibPipenv 安装 matplotlib
【发布时间】:2018-03-19 15:43:57
【问题描述】:

我在我的 pipenv 中安装 matplotlib 时遇到了很多困难,我相信是由于非 python 依赖项。

我得到的错误是

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. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.

这是在 MacOS X (High Sierra) 上。我已经通过 brew 安装了 libpng freetypepkg-config,但这似乎并不能解决问题。

我希望这个 pipenv 能够部署到 Heroku,如果这有什么不同的话。

【问题讨论】:

  • 你是在 virtualenv 里面运行这个吗?你也安装了 pyenv 吗?
  • 您是否通过osx_framework 推荐的步骤?
  • 我已经安装了 pyenv。我试图遵循这些步骤@ImportanceOfBeingErnest 但是我承认我发现它们很难理解,我不确定要实施哪些。任何建议将不胜感激
  • 是的,该评论旨在让您更新有关这些步骤的确切问题所在的问题。 (我没用mac,所以我个人帮不了你,但我可以帮你写一个问题,别人可能更容易掌握)

标签: python macos matplotlib pipenv


【解决方案1】:

在按照@brian 的建议尝试之前,对我来说,只需在import matplotlib 之后和from matplotlib import pyplot 之前添加matplotlib.use('TkAgg') 就可以了

import matplotlib
matplotlib.use('TkAgg')
from matplotlib import pyplot

环境

  • 这是在 MacOS X (High Sierra) 上
  • Python 3.7 版本
  • pipenv,版本 2018.7.1

【讨论】:

    【解决方案2】:

    我按照this answer 中的说明解决了此错误,同时还使用this document 查找matplotlibrc 文件所在的位置。

    要在我的 pipenv 中执行此操作,我运行了以下代码:

    python
    >>> import matplotlib
    >>> matplotlib.matplotlib_fname()
    

    使用输出导航到我的虚拟环境中的 matplotlibrc 文件并将backend: TkAgg 添加到文件中。

    这解决了我的问题。希望这个问题可以对其他人有所帮助!

    【讨论】:

      猜你喜欢
      • 2018-11-09
      • 2019-03-15
      • 2019-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-14
      • 2021-02-12
      相关资源
      最近更新 更多