gpt4 book ai didi

python - 导入 matplotlib 失败,在 heroku 上没有名为 _tkinter 的模块

转载 作者:太空狗 更新时间:2023-10-29 17:32:17 26 4
gpt4 key购买 nike

我正在尝试在我的应用程序中使用 matplotlib。我在python2.7中创建了一个virtualenv,pip安装了matplotlib,在本地成功运行。

但是,当我将应用程序部署到 heroku 时(在 pip freeze 和其他必要步骤之后),我的应用程序崩溃了。当我查看日志时,我看到以下内容:

import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter

这很奇怪,因为该应用程序在 venv 下在本地成功运行。 heroku python环境没有配置运行matplotlib?如果是这样,我应该采取什么步骤来启用它?

最佳答案

这应该可以解决问题

matplotlib.use('Agg')
import matplotlib.pyplot as plt

这将设置您的 Matplotlib backend使用 Agg 而不是 Tk。至少对我有用:-)

关于python - 导入 matplotlib 失败,在 heroku 上没有名为 _tkinter 的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41319082/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com