- How to install tkinter for python 3.8?
- 5 Answers 5
- Pip Install Tkinter
- Pre-requisites
- Python
- Pip
- Check for Built-in Tkinter Package
- Installing Tkinter with Pip
- Testing the Tkinter Package
- Conclusion
- About the author
- Abdul Mannan
- 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
- Install Tkinter
- Install Tkinter on Windows
- Install Tkinter on Linux
- Install Tkinter on Mac Operating System
- Install Tkinter in Pycharm
How to install tkinter for python 3.8?
I have Python 3.8 on Ubuntu 16.04. I installed python3-tk (it is required for showing plots in matplotlib):
Reading package lists. Done Building dependency tree Reading state information. Done python3-tk is already the newest version (3.5.1-1). 0 upgraded, 0 newly installed, 0 to remove and 12 not upgraded.
Reading package lists. Done Building dependency tree Reading state information. Done python3.8-tk is already the newest version (3.8.2-1+xenial1). 0 upgraded, 0 newly installed, 0 to remove and 12 not upgraded.
$ python3.8 -m tkinter Traceback (most recent call last): File "/usr/local/lib/python3.8/runpy.py", line 184, in _run_module_as_main mod_name, mod_spec, code = _get_module_details(mod_name, _Error) File "/usr/local/lib/python3.8/runpy.py", line 143, in _get_module_details return _get_module_details(pkg_main_name, error) File "/usr/local/lib/python3.8/runpy.py", line 110, in _get_module_details __import__(pkg_name) File "/usr/local/lib/python3.8/tkinter/__init__.py", line 36, in import _tkinter # If this fails your Python may not be configured for Tk ModuleNotFoundError: No module named '_tkinter'
5 Answers 5
If you installed python3.8 using apt (via ppa:deadsnakes/ppa), it can be installed using apt too, the name of library is python3.8-tk .
sudo apt install python3.8-tk
In my case, it solves the problem. For instance, now I can use matplotlib in python3.8 which requires tkinter.
Recompile and reinstall python3.8 specifying path to folders with tcl, tk includes and libraries.
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev python-tk python3-tk tk-dev cd ~/Downloads wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz tar -xvf Python-3.8.2.tgz cd Python-3.8.2
Edit ./configure file the next way: replace . for next lines:
--with-tcltk-includes='-I/usr/include' --with-tcltk-libs='-L/usr/lib' ./configure make -j2 # replace 2 by number of processor cores you have sudo make install $ python3.8 Python 3.8.2 (default, May 11 2020, 14:30:03) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter >>>
Python 3.8 installed through apt and pyenv on 16.04 does not include tkinter, as I think or there’s a some bug that does not allow to import it. Only rebuilding helped. Previously I’ve used 20.04 with built in Python 3.8 version, which supports tkinter with only additional packages installing as it is for Python 3.5 on 16.04.
python3.8-tk installation as Ankur A Sharma said is also required. I’ve forget to mention it. But it is not sufficient for 16.04, at least in my case.
Additional requirement from OP’s comment:
sudo ./configure --with-tcltk-includes='-I/usr/include -I/usr/include/tcl' --with-tcltk-libs='-L/usr/lib -ltcl -ltk' --enable-optimizations
Pip Install Tkinter
The “Tkinter” package/library of python is used to develop the Graphical User Interfaces of python-based applications with great ease and control. What most people don’t realize is that the Tkinter package comes pre-installed in python 3.7 or higher, and if that is not the case, then it can be separately downloaded using the Pip commands.
Pre-requisites
There are a few pre-reqs for installing and using the Tkinter Package, and these pre-reqs include:
Python
Python must be installed in the user’s PC to not only install Tkinter but also to use it. To verify if python is installed on the PC or not, run the following command inside a Command Prompt or any other terminal:
The above command will produce the following results if python is installed:
Pip
After python, ensure that pip is also installed on the PC by using the following command inside the Command Prompt or any other terminal:
The output confirms that pip is installed on the user’s PC.
Check for Built-in Tkinter Package
As mentioned above, the Tkinter package also comes pre-installed with python 3.7 and higher. This essentially means that the user might not need to explicitly install the Tkinter package as it may already be installed on his machine. To verify this, run the following command inside the Command Prompt:
If the tkinter package is already installed, then the above command will result in the following output:
If the output is an error, then that means that the tkinter package is not pre-installed on your PC.
Installing Tkinter with Pip
Once you have made sure that you have all the prerequisites installed and also that there is no built-in tkinter with your python package, simply install the Tkinter using the following pip command:
Alternatively, you can also use the following command:
Both of the above commands will download and install the Tkinter package on your PC:
Testing the Tkinter Package
To test that the tkinter package has been successfully installed and is working, simply open up a python shell, by typing in “python” in a command prompt window:
After that, import the tkinter package and launch a new frame using the following lines:
After that, the following window will open up:
The window contains a demo GUI from the tkinter package, which contains two buttons, “Click me!” and “QUIT,” and two statements that display the version of the TK or the TCL package. The current version installed is the “Tcl 8.6”
Conclusion
The “pip install tkinter” command is used to install the tkinter package in python, a Graphical User Interface builder package that provides many features to the developer. However, this Tkinter package, also known as Tcl or TK package, comes as a built-in module with python 3.7 and higher. Therefore, the user might not necessarily need to install the tkinter package separately. This post has pictorially represented the purpose and the usage for the “pip install tkinter” command.
About the author
Abdul Mannan
I am curious about technology and writing and exploring it is my passion. I am interested in learning new skills and improving my knowledge and I hold a bachelor’s degree in computer science.
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
Install Tkinter
- Install Tkinter on Windows
- Install Tkinter on Linux
- Install Tkinter on Mac Operating System
- Install Tkinter in Pycharm
This tutorial will demonstrate how to install Tkinter on multiple platforms. Every platform has individual commands to install Tkinter in Python.
Install Tkinter on Windows
Tkinter offers multiple GUI libraries to develop GUI applications. The Tkinter is one of the popular libraries to build GUI system interfaces.
To install Tkinter, we have to install Python; if it is already installed, we can move on to install Tkinter. When we start the installation of Python, we can check td or tk and IDLE Tkinter during installation.
This way, this Tkinter will come along with Python packages, and we do not need to install it separately. However, if we lose installing Tkinter during the installation of Python, we can do it later using the pip command.
We can confirm the Python version using this command.
Pip ’s version is checked using this command.
Now we are ready to install Tkinter.
Now we can use the tkinter library. To confirm the tkinter library is installed, write the code in the shell.
import tkinter tkinter._test()
If you are an Anaconda user, you can use the following command.
conda install -c anaconda tk
Install Tkinter on Linux
There are different variants of the Linux operating system. This section will learn how to install Tkinter in multiple variants.
Use this command if you’re using a Debian-based Linux operating system.
# python2 user sudo apt-get install python-tk
# python3 user sudo apt-get install python3-tk
Use this command if you’re using one of these: RHEL, CentOS, Oracle Linux.
sudo yum install -y tkinter tk-devel
The Fedora-based Linux operating system uses this command.
Use this command to confirm the tkinter library is installed successfully.
Install Tkinter on Mac Operating System
There are two ways to install the tkinter library in MacOS. The Mac user will follow these steps.
Run the below command to check that python3 is installed.
Run the below command to check that pip3 is installed.
If your pip is outdated, please upgrade your pip using the below command.
We will use pip3 as the first method. Write the following command to install Tkinter.
The second method needs a setup.py file to install the Tkinter.
We have to download the latest version of Tkinter in python3 using this command.
curl https://files.pythonhosted.org/packages/a0/81/ 742b342fd642e672fbedecde725ba44db44e800dc4c936216c3c6729885a/tk-0.1.0.tar.gz > tk.tar.gz
Write the following command to extract the downloaded package.
Go to the extracted folder and run this command.
To ensure the tkinter library is installed, run this code in the Python terminal.
Install Tkinter in Pycharm
The installation process is very simple in Pycharm IDLE. Pycharm IDLE is more convenient for users.
There is an interface to install the tkinter library without running a command.
Go to File>Settings>Project>Python Interpreter and click the + button, search tk , and click the Install Package button. You can select the specific version.
Click here to read more about Tkinter.
Hello! I am Salman Bin Mehmood(Baum), a software developer and I help organizations, address complex problems. My expertise lies within back-end, data science and machine learning. I am a lifelong learner, currently working on metaverse, and enrolled in a course building an AI application with python. I love solving problems and developing bug-free software for people. I write content related to python and hot Technologies.