Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install Tkinter On Amazon Linux

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?

like image 572
Swetabh Avatar asked Nov 18 '16 11:11

Swetabh


People also ask

Is tkinter available for Linux?

Tkinter can be installed in other Linux based distributions from the package manager. You can also install Tkinter packages in Linux by following installation instructions available here.

How do I use tkinter in Linux?

Tkinter is one of the widely used libraries for creating GUI-based applications. In order to create applications using Tkinter, we have to install and import the library in the notebook. First, we have to install the tkinter library in our local environment based on the Windows or Linux operating system.

How do I install tkinter on Ubuntu?

Instructions for Ubuntu Install Tkinter: apt-get install python-tk (restart after) Install setuptools: sudo apt-get install python-setuptools. Install suds: sudo easy_install suds. Install matplotlib: sudo apt-get install python-matplotlib.

How do I know if tkinter is installed on Linux?

Running python -m tkinter from the command line should open a window demonstrating a simple Tk interface, letting you know that tkinter is properly installed on your system, and also showing what version of Tcl/Tk is installed, so you can read the Tcl/Tk documentation specific to that version.


3 Answers

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".

like image 117
Stop harming Monica Avatar answered Oct 16 '22 09:10

Stop harming Monica


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()
like image 29
z-star Avatar answered Oct 16 '22 08:10

z-star


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

like image 2
Roberto García Avatar answered Oct 16 '22 07:10

Roberto García