Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModuleNotFoundError: No module named '_tkinter' when installing python 3.12.0 using pyenv in Fedora 38

I'm tryiny to install latest python 3.12.0 in Fedora 38 using pyenv. The command is pyenv install 3.12.0

I get below 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

I also installed tkinter in fedora but its 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 I fix this error?

Note:

OS 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
like image 706
Rajkumar Natarajan Avatar asked Oct 16 '25 21:10

Rajkumar Natarajan


1 Answers

Update your system's package list and install the required packages

sudo dnf update
sudo dnf install tk-devel

Set the TCL_LIBRARY and TK_LIBRARY environment variables. You can do this in your shell configuration file (e.g., ~/.bashrc or ~/.zshrc) or set them temporarily for your session. Replace <path_to_tcl> and <path_to_tk> with the actual paths

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

Open a new terminal to apply changes

pyenv install 3.12.0

This should allow you to build Python 3.12.0 with Tkinter support

like image 97
Thanks10414 Avatar answered Oct 19 '25 11:10

Thanks10414



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!