Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 导入matplotlib失败,heroku上没有名为_tkinter的模块_Python_Heroku_Matplotlib_Tkinter - Fatal编程技术网

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