Python 导入matplotlib失败,heroku上没有名为_tkinter的模块
我试图在我的应用程序中使用Python 导入matplotlib失败,heroku上没有名为_tkinter的模块,python,heroku,matplotlib,tkinter,Python,Heroku,Matplotlib,Tkinter,我试图在我的应用程序中使用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 nam
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使用Agg而不是Tk。至少对我有用:-)为了正确起见,
先导入matplotlib
再导入其他内容。此外,您需要确保将此行放在可能也导入matplotlib的任何其他包之前,例如skimage