Install Tkinter On Amazon Linux

2020-03-01 07:21发布

I am working on an Amazon Linux ec2 machine. When I try to run a Python script inside a virtualenv, I get the following message:

File "/home/sp/Envs/crispor/local/lib/python2.7/dist-packages/matplotlib/externals/six.py", line 80, in _import_module
__import__(name)
ImportError: No module named Tkinter

As I understand Tkinter should have been a part of the Python installation. But somehow it is not. These do not work -

sudo yum install python-tk
sudo yum install tkinter

How do I install Tkinter? Or should I be doing that at all give it should have been a part of the Python installation?

3条回答
一夜七次
2楼-- · 2020-03-01 07:54

Could you give python version information?

1- Try to install this:

yum install python-tools

This package uses tkinder so can help.

2- If you use python3:

sudo yum install python3-tkinter

3- Download and install the package: http://rpm.pbone.net/index.php3?stat=3&search=python27-tkinter&srodzaj=3&dist[]=79

查看更多
乱世女痞
3楼-- · 2020-03-01 07:58

to add to @Goyo. you can switch the mode to agg in code as well.

import matplotlib
matplotlib.use('agg',warn=False, force=True)
from matplotlib import pyplot as plt
print "Switched to:",matplotlib.get_backend()
查看更多
地球回转人心会变
4楼-- · 2020-03-01 08:03

You don't want (and probably you can't) install tkinter in that server. Configure matplotlib to use a non-interactive backend instead.

Put this in your matplotlibrc file:

backend : agg

UPDATE This should not be necessary for matplotlib >= 3.0.0, according to the documentation "[h]eadless linux servers (identified by the DISPLAY env not being defined) will not select a GUI backend".

查看更多
登录 后发表回答