Error encountered while searching for module 'tkinter' during the installation of Python version 3.12.0 with pyenv on Fedora 38

Trying to install the latest version of Python 3.12.0 on Fedora 38 using pyenv with the command pyenv install 3.12.0

Encountering the following error -

~ pyenv install 3.12.0  
  Downloading Python-3.12.0.tar.xz...
  -> https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tar.xz
  Installing Python-3.12.0...
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/home/raj/.pyenv/versions/3.12.0/lib/python3.12/tkinter/__init__.py", line 38, in <module>
      import _tkinter # If this fails your Python may not be configured for Tk
      ^^^^^^^^^^^^^^^
  ModuleNotFoundError: No module named '_tkinter'
  WARNING: The Python tkinter extension was not compiled and GUI subsystem has been detected. Missing the Tk toolkit?
  Installed Python-3.12.0 to /home/raj/.pyenv/versions/3.12.0

Tried installing tkinter in Fedora but it seems the version is 3.11.6.

 ~ sudo dnf install python3-tkinter -y        
  Last metadata expiration check: 1:29:18 ago on Tue 17 Oct 2023 09:30:15 PM PDT.
  Package python3-tkinter-3.11.6-1.fc38.x86_64 is already installed.
  Dependencies resolved.

How can this error be fixed?

Note:

Operating System Details

~ lsb_release -a     
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: Fedora
Description:    Fedora release 38 (Thirty Eight)
Release:        38
Codename:       ThirtyEight

pyenv version

~ pyenv --version    
pyenv 2.3.30

Answer №1

Make sure to update your system's package list and install all the necessary packages

sudo apt-get update
sudo apt-get install tk-dev

Don't forget to set the TCL_LIBRARY and TK_LIBRARY environment variables. You can either do this in your shell configuration file (such as ~/.bashrc or ~/.zshrc) or set them temporarily for your current session. Replace <path_to_tcl> and <path_to_tk> with the correct paths

export TCL_LIBRARY="<path_to_tcl>/lib"
export TK_LIBRARY="<path_to_tk>/lib"

After making these changes, open a new terminal window

pyenv install 3.12.0

By following these steps, you should be able to successfully compile Python 3.12.0 with Tkinter support

Answer №2

If you're facing this issue on macOS as well (which is why I landed here), it might look something like this:

python-build: use openssl@3 from homebrew
python-build: use readline from homebrew
Downloading Python-3.12.2.tar.xz...
-> https://www.python.org/ftp/python/3.12.2/Python-3.12.2.tar.xz
Installing Python-3.12.2...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/me/.pyenv/versions/3.12.2/lib/python3.12/tkinter/__init__.py", line 38, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
    ^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named '_tkinter'
WARNING: The Python tkinter extension was not compiled and GUI subsystem has been detected. Missing the Tk toolkit?
Installed Python-3.12.2 to /Users/me/.pyenv/versions/3.12.2

It's important to note that a line is missing:

python-build: use tcl-tk from homebrew
. As suggested by https://github.com/pyenv/pyenv/wiki#suggested-build-environment, along with XCode Command Line tools, you should also have:
brew install openssl readline sqlite3 xz zlib tcl-tk

After installing tcl-tk, running python install 3.12 again should resolve the issue.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to adjust the background color

Is there a way to change the background color instead of font color in this code snippet? def cloud_height_style_function(vals): return pd.cut(vals,[-np.inf,199,499,999,3000, np.inf], # need to review the bin a bit labels=[f'color: ...

What is the most suitable data structure for storing an array of dictionaries?

Looking to create a data structure that follows this format: { key: {k: v for k in range(fixed_small_number)} for key in range(fixed_large_number) } I am taking an "eclectic" approach, adding one item at a time to a random k for a random key. Thi ...

Finding the reason behind an object's failure to adhere to a specific Protocol

Imagine there is a protocol called Frobbable that has both a valid and a broken implementation, where the broken one is missing the .frob() method: from typing import Protocol from abc import abstractmethod class Frobbable(Protocol): @abstractmethod ...

What is causing the "invalid syntax" error with this basic if-else code?

My Python code seems to be giving an error when using the else statement. Here's what it looks like: a = 3 if a == 3: print("a is 3") print("yes") else: print("a is not 3") I'm getting an invalid syntax error specifically for the else: pa ...

Are there some arguments that are not being converted in the string formatting process?

Here is some code I have written: print(*(i for index, i in enumerate(list(input(int()).split())) if i % 6 == 0 and (index+1) % 6 == 0), sep=' '`) Although my code looks fine, I am encountering the following error: TypeError: not all argumen ...

A step-by-step guide to displaying a list of HTML page titles with clickable links on the homepage using Django

Snapshot of my window view I apologize if this question seems simple, but I am still learning about Django. I am currently in the process of creating a website where articles are stored as template files. My goal is to showcase all article titles on the h ...

Leveraging networkX for generating a hierarchical tree diagram

Currently, I am utilizing networkX to create a tree structure, following the guidance provided in this insightful response. import networkx as nx import matplotlib.pyplot as plt G = nx.DiGraph() G.add_node("ROOT") for i in range(5): G.add_node("Child ...

Removing the Add button from inline forms in Django 1.7

I'm currently facing an issue with a seemingly simple task. I have editable models (Prodotto, Comune) displayed as "addable" fields in the form below. However, I want to remove the + (add) button for these specific fields without disabling the ability ...

The dashboards list could not be loaded due to an error in decoding the JSON format within Apache Superset

I encountered an issue while fetching dashboards in Superset. The error message states: ERROR:root:Expecting ',' delimiter: line 1 column 106 (char 105) I observed this error while monitoring the pod. On the front-end, only the following messa ...

Is there a way to transform my output into a list structure?

I am struggling to transform my result into the desired format: [5130, 5415, 5700, 5985, 6270, 6555, 6840, 7125, 7410, 7695, 7980] but I keep getting: 5130 5415 5700 5985 6270 6555 6840 7125 7410 7695 7980 I'm unsure how to make the conversion. The ...

What is the Python method for determining if a PDF page contains color?

I need help determining the number of coloured and non-coloured (black and white) pages in a PDF file. How can this be achieved? For instance, if I upload a 100-page PDF file, it should provide me with the count of X coloured pages and Y non-coloured page ...

Finding the average time from a given list of times

Hey there! I'm currently facing an issue with calculating the average time from a list of times for each test. Can you help? Here's the output: test1 ['0:02:30.000000', '0:02:28.000000', '0:02:31.000000', '0:02 ...

Sending checkbox value with jquery.ajax in Bootstrap modal: a step-by-step guide

Currently I am facing a challenge with a form that includes a checkbox on a webpage pop-up modal using flask/bootstrap/jquery. My goal is to submit the form without refreshing the page, which is why I'm utilizing jquery.ajax for this task. Despite the ...

Displaying dataframes with Pandas

While attempting to follow the "Machine Learning" tutorial by Microsoft, I encountered an issue during the practical part. I simply copied the code and tried running it from the Linux terminal, but unfortunately, nothing was returned. The video demonstrati ...

moving data from tkinter entry fields

Is it possible to access the output of an entry field created within one function in another function? def test1(): registerWindow = Toplevel() username_entry = Entry(registerWindow, width=30) username_entry.pack() register_btn = Button(r ...

The tab functionality in Python Selenium is effective when using Firefox, however, when using Chrome, it

I have been working on a script that is designed to open multiple websites in new tabs. Initially, everything seemed to work perfectly in Firefox. However, when testing the script on Chrome, I encountered an issue. It opens a new tab as expected but the l ...

Difficulty integrating a Python solution with a C++ component in Visual Studio 2017

When attempting to open the twslink2pt.sln project/solution (a Python 3.6 wrapper with a c++ component) using Visual Studio 2017, an error message is displayed. 1>------ Build started: Project: twslink2pt, Configuration: Release Win32 ------ 1>Per ...

The submit button in Python 3 seems to be malfunctioning. What steps can I take to fix this issue

import tkinter as tk from tkinter import * import tkinter.ttk class main_window(Frame): def __init__(self): tk.Frame.__init__(self) self.pack() self.master.title("MANAGEMENT") self.entry_button = But ...

Resolving the Django REST problem: Implementing additional actions with ListApiView

Working on a new project utilizing the Django REST API framework. Encountering an error when running the project locally: File "/home/asad/PycharmProjects/microshop/venv/lib/python3.8/site-packages/rest_framework/routers.py", line 153, in get_rou ...

Designing a Chess Program with Object-Oriented Principles

I've been working on my chess program and I have a class called Move, which keeps track of where a piece was moved from and to. It also stores information about the pieces involved in the move. However, I'm facing an issue where I have to pass t ...