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?
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.
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.
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.
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.
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".
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()
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With