Tkinter: Python may not be configured for Tk
According to http://wiki.python.org/moin/TkInter :
If it fails with "No module named _tkinter", your Python configuration needs to be modified to include this module (which is an extension module implemented in C). Do not edit Modules/Setup (it is out of date). You may have to install Tcl and Tk (when using RPM, install the -devel RPMs as well) and/or edit the setup.py script to point to the right locations where Tcl/Tk is installed. If you install Tcl/Tk in the default locations, simply rerunning "make" should build the _tkinter extension.
import _tkinter # If this fails your Python may not be configured for Tk error in python 3.8
Resolved the issue it occurred because the Tkinter was installed for version 3.5 and not for the 3.8 version. For that, I installed the 3.5 version and kept only one version i.e. 3.8, and installed Tkinter again, and it worked!
This is just a workaround to make things work, but the more preferred way is to create a venv and then install the particular versions of python and libraries that are needed.
Python not configured for Tk
You need to have the Tk development files/headers available during pyenv install
.
On Ubuntu (15.04) the following should provide them: sudo apt-get install tk-dev
.
After this, pyenv install 3.4.3
(or pyenv install 2.7.10
etc) should pick it up and have support for Tk.
(Reference issue in pyenv)
When running python 3.9.4 I am unable to import tkinter, but downgrading to 3.8.2 works perfectly fine
Looks like tkinter is disabled in brew for python 3.9 but not for 3.8,
it's commented on their github.
Try the python-tk formula if you want to use python 3.9.
ImportError: No module named 'Tkinter'
You probably need to install it using something similar to the following:
For Ubuntu or other distros with Apt:
sudo apt-get install python3-tk
For Fedora:
sudo dnf install python3-tkinter
You can also mention a Python version number like this:
sudo apt-get install python3.7-tk
sudo dnf install python3-tkinter-3.6.6-1.fc28.x86_64
Finally, import tkinter
(for Python 3) or Tkinter
(for Python 2), or choose at runtime based on the version number of the Python interpreter (for compatibility with both):
import sys
if sys.version_info[0] == 3:
import tkinter as tk
else:
import Tkinter as tk
Related Topics
Why Is Dictionary Ordering Non-Deterministic
How to Log While Using Multiprocessing in Python
How to Directly Send a Python Output to Clipboard
Run a Linux System Command as a Superuser, Using a Python Script
How to Execute Raw SQL in Flask-Sqlalchemy App
Parse a .Py File, Read the Ast, Modify It, Then Write Back the Modified Source Code
How to Open a File for Both Reading and Writing
Performance of Pandas Apply VS Np.Vectorize to Create New Column from Existing Columns
How to Access the Query String in Flask Routes
How to Validate a Url with a Regular Expression in Python
How to Specify New Lines on Python, When Writing on Files
How to Validate Ip Address in Python
How to Run an External Command Asynchronously from Python
Is Shared Readonly Data Copied to Different Processes for Multiprocessing
How to Execute a File Within the Python Interpreter
Way to Change Google Chrome User Agent in Selenium