- Install tkinter for Python [duplicate]
- 25 Answers 25
- Install Tkinter on Ubuntu Linux Install Tkinter on Ubuntu and other Debian-based Linux distributions
- Install Tkinter via apt
- Purchasing Power Parity
- Never miss an update
- How to Install Python Tkinter on Linux
- Prerequisites
- Install Tkinter in Linux
- Verify the Tkinter installation
- Running an Example with Tkinter
Install tkinter for Python [duplicate]
I could probably install it using synaptic manager (can I?), however, I would have to install it on every machine I program on. Would it be possible to add the Tkinter library into my workspace and reference it from there?
did the solution the answer suggested work for u? It did not for me: E: Unable to locate package python-tk did anyomne have this issue?
For what it’s worth, if you get this error with matplotlib it is not always necessary to install Tkinter. Call matplotlib.use(‘Agg’) right after importing matplotlib .
You can use import matplotlib matplotlib.use(‘agg’) import matplotlib.pyplot as plt if you dont wish to install tkinter
I am using python 3.8 and I still cannot import Tkinter: Tried sudo apt-get install python-tk and sudo apt-get install python3.8-tk but not able to see it in pycharm (using a virtual environment) Reading package lists. Done Building dependency tree Reading state information. Done Note, selecting ‘python3-tk’ instead of ‘python3.8-tk’ python3-tk is already the newest version (3.6.9-1~18.04). 0 upgraded, 0 newly installed, 0 to remove and 19 not upgraded.
25 Answers 25
It is not very easy to install Tkinter locally to use with system-provided Python. You may build it from sources, but this is usually not the best idea with a binary package-based distro you’re apparently running.
It’s safer to apt-get install python-tk on your machine(s). (Works on Debian-derived distributions like for Ubuntu; refer to your package manager and package list on other distributions.)
@BryanOakley: Certainly. The poster seemed to have an apt-based Linux box, thus the answer. This looked like a narrow problem. I didn’t expect this answer to get so many upvotes.
Just did this exercise on Mint18 (derived from 16.04 Ubuntu) and it was doubleplusgood. sudo apt install -y python3-tk
How does one install tkinter from sources? I have tcl/tk, verified using wish . I can’t find the source tarball for tkinter.
Actually, you just need to use the following to install the tkinter for python3:
sudo apt-get install python3-tk
In addition, for Fedora users, use the following command:
sudo dnf install python3-tkinter
If you’re a Linux newbie like me, note that if apt-get has problems finding / installing python3-tk, try running sudo apt-get update first. In my 32-bit Linux Mint 18.3 system, Synaptic and apt-get seem to require that more often than I would have supposed.
I get python3-tk is already the newest version (3.5.1-1) and when i import tkinter I still get: ModuleNotFoundError: No module named ‘tkinter’ I Use(Python 3.7.5)
If, like me, you don’t have root privileges on your network because of your wonderful friends in I.S., and you are working in a local install you may have some problems with the above approaches.
I spent ages on Google — but in the end, it’s easy.
Download the tcl and tk from http://www.tcl.tk/software/tcltk/download.html and install them locally too.
To install locally on Linux (I did it to my home directory), extract the .tar.gz files for tcl and tk. Then open up the readme files inside the ./unix directory. I ran
cd ~/tcl8.5.11/unix ./configure --prefix=/home/cnel711 --exec-prefix=/home/cnel711 make make install cd ~/tk8.5.11/unix ./configure --prefix=/home/cnel711 --exec-prefix=/home/cnel711 --with-tcl=/home/cnel711/tcl8.5.11/unix make make install
It may seem a pain, but the files are tiny and installation is very fast.
Then re-run python setup.py build and python setup.py install in your python installation directory — and it should work. It worked for me — and I can now import Tkinter etc to my heart’s content — yipidy-yay. An entire afternoon spent on this — hope this note saves others from the pain.
Hi Simon. I just get off the boad of linux. I need to install tcl/tk and python locally. I want to install them to «/home/cnel711/install/». After Installing the tcl/tk. should I set the path for Python? and how. I also use ./configure to install python. thanks
Hi I already have tcl/tk installed locally and I rebuilt python. But, while building python(locally), I am getting an error: libtk8.6.so: cannot open shared object file: No such file or directory, and that the module _tkinter has failed to be built. I even tried setting the path to my tcl/tk libraries with —with_tcltk_libs but this didn’t help.
@DavidMerinos, I suppose the setup.py file is to be found in the source directory where you originally installed Python — it is where I found it. If you didn’t delete it but forgot where this directory is, you can run a find ~ -type f -name setup.py command from anywhere your shell.
If you are using Python 3 it might be because you are typing Tkinter not tkinter
For Arch Linux users, it goes a bit like
you will need the package and its dependencies.
since you mentioned synaptic, you must be using a Debian based system. one way to get what you need:
sudo apt-get install python-tk
You don’t need to download Tkinter — it’s an integral part of all Python distributions (except binary distributions for platforms that don’t support Tcl/Tk).
In my case, on Windows, what helped was reinstalling the Python distribution. A long time ago, I had unchecked the «Tcl/Tk» installation feature. After reinstalling, all works fine and I can import _tkinter and import Tkinter .
If you’re using RHEL, CentOS, Oracle Linux, etc. You can use yum to install tkinter module
On CentOS 7, I have installed tkinter but still my default python (2.7) complains «No module named tkinter»!
For python 3.7 on ubuntu I had to use sudo apt-get install python3.7-tk to make it work
for python3 user, install python3-tk package by following command sudo apt-get install python3-tk
tk-devel also needs to be installed in my case
install these and rebuild python
Fedora release 25 (Twenty Five)
dnf install python3-tkinter
@mikeymop, I didnt mean it is not working on F26. Instead wanted to be very clear and specific on the working condition.
There is _tkinter and Tkinter — both work on Py 3.x But to be safe- Download Loopy and change your python root directory(if you’re using an IDE like PyCharms) to Loopy’s installation directory. You’ll get this library and many more.
If you’re using Python 3 then you must install as follows:
sudo apt-get update sudo apt-get install python3-tk
Tkinter for Python 2 ( python-tk ) is different from Python 3 ‘s ( python3-tk ).
@MatthewRead I changed it. I left it there by accident and you are right. I doesn’t have anything to do with the installation process of Tk.
Tkinter is a GUI module for python. you can use it to make GUI based applications in python. Tkinter provides several GUI widgets like buttons,menu, canvas,text,frame,label etc. to develop desktop applications.Though Tkinter is very popular and is included with windows, macosx install of python, There are also alternative choices like pyQt, wxPython.
In this tutorial we will see how to install it on linux and use it with an example.
First, check if you have python installed and also check its version
Open up your terminal and type python. if its installed then it will show information like version, help. check your version (mine is python 2.7.9)
aman@vostro:~$ python Python 2.7.9 (default, Apr 2 2015, 15:33:21) [GCC 4.9.2] on linux2 Type «help», «copyright», «credits» or «license» for more information.
If you don’t have python then install it sudo apt-get install python
If you want to install python 3 then enter the following. If you are a newbie, I would recommend python 2 instead of python 3. Python 2 is still very popular and many apps are made on it. On ubuntu python2 is still the default sudo apt-get install python3
sudo apt-get install python-tk
sudo apt-get install python3-tk
Now, lets check if Tkinter is working well with this little example
open your terminal and enter into your python shell. python
if python was installed correctly you will get a >>> prompt. aman@vostro:~$ python
Python 2.7.9 (default, Apr 2 2015, 15:33:21) [GCC 4.9.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
Now import Tkinter module. it wont show any error if it got imported correctly. NOTE: Make sure you type Tkinter (not tkinter) in python2 and tkinter (not Tkinter) in python3.
Now, just to check you can create an empty window using Tkinter.
Install Tkinter on Ubuntu Linux
Install Tkinter on Ubuntu and other Debian-based Linux distributions
Before you start the Tkinter tutorial you will need to have a working installation of PyQt5 on your system. If you don’t have either set up yet, the following steps will guide you through how to do this on Linux.
This guide is also available for macOS. On Windows, Tkinter is installed by default with Python.
Install Tkinter via apt
Packages for Tkinter are available in the repositories of most distributions. In Ubuntu you can install either from the command line or via «Software Center». The package you are looking for is named python3-tk .
You can also install these from the command line as follows —
sudo apt install python3-tk
After install is finished, you should be able to run python3 (or python ) and import tkinter without errors.
Python 3.7.6 Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter >>>
Downloadable ebook (PDF, ePub) & Complete Source code
[[ discount.discount_pc ]]% OFF for the next [[ discount.duration ]] [[discount.description ]] with the code [[ discount.coupon_code ]]
Purchasing Power Parity
Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]
Never miss an update
Enjoyed this? Subscribe to get new updates straight in your Inbox.
Install Tkinter on Ubuntu Linux was written by Martin Fitzpatrick .
Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt.
Install Tkinter on Ubuntu Linux was published in installation on May 21, 2019 (updated March 16, 2023 )
- Topics
- Where do I begin?
- Data Science
- Packaging & Distribution
- Databases & SQL
- QML/QtQuick
- Learn the fundamentals
- Raspberry Pi
- Games
- Start
Follow us for new tutorials
How to Install Python Tkinter on Linux
Tkinter is a Python library that is used to create graphical user interfaces (GUIs). It is a standard Python interface to the Tk GUI toolkit, which is widely used in the Linux operating system. In this tutorial, we will learn how to install Tkinter on a Linux system using either pip or apt-get.
Prerequisites
To install Python’s Tkinter module on a Linux system, you will need to have the following prerequisites installed:
- Python: Tkinter is a module for Python, so you will need to have Python installed on your system. Most Linux distributions come with Python pre-installed, but if you don’t have it installed you can use your distribution’s package manager to install it.
- Tcl/Tk: Tkinter is built on top of the Tcl/Tk libraries, so you will need to have these libraries installed in order to use Tkinter. Most Linux distributions come with Tcl/Tk pre-installed, but if you don’t have them installed you can use your distribution’s package manager to install them.
- A development environment: In order to install Tkinter, you will need to have a development environment set up on your system. This typically includes a compiler (such as GCC) and the make utility. If you don’t have these tools installed, you can use your distribution package manager to install them.
Install Tkinter in Linux
Python Tkinter library packages are available under the default package repositories. You can install it using the system’s package manager to install the Python Tkinter module based on the operating system.
- On Debian-based Linux (Ubuntu, Debian, Pop!_OS):
sudo apt-get install python3-tk
sudo yum install -y tkinter tk-devel
sudo dnf install python3-tkinter
This will install the Tkinter module on your system.
Verify the Tkinter installation
Once the Python Tkinter module is successfully installed on your system. The following command will show you the Tkinter versions.
The below screenshot shows that Python Tkinter 8.6 is installed.
Running an Example with Tkinter
Let’s make a sample Python program using the Tkinter module. Create a file `example.py` file with the following content.