I am trying to install (through pyenv) Python-3.11.4 under CentOS-7. It installs but without GUI. I get the following error message:
Installing Python-3.11.4...
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/.../pyenv/versions/3.11.4/lib/python3.11/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.11.4 to /.../pyenv/versions/3.11.4
While Python-3.9.16 installs successfully on the same machine. According to Python 3.11 Build Changes, the requirement is to have "Tcl/Tk version 8.5.12 or newer" installed. I have
$ rpm -q tk tk-devel
tk-8.5.13-6.el7.x86_64
tk-devel-8.5.13-6.el7.x86_64
The same page says "Tcl/Tk, and uuid flags are detected by pkg-config (when available). tkinter now requires a pkg-config command to detect development settings for Tcl/Tk headers and libraries.", which is also installed:
$ rpm -q pkgconfig
pkgconfig-0.27.1-4.el7.x86_64
Could you please help me to understand what might be the reason of the failure to install _tkinter
?
Thank you very much for your help!
2
Answers
To build successfully Python-3.11.4 under CentOS-7, one needs to set the following environment variables:
where the
openssl11
parts are needed for the_ssl
module, and the rest is needed for the_tkinter
module.The pieces needed to build Python with the Tk/Tcl were found in
To check if
tkinter
was built successfully, do the following:It seems, the root cause of the problem is that
tcl
andtk
rpm packages in CentOS-7 do not provide the correspondingpkg-config
files:and so one has to provide the corresponding information manually.
What fixed it for me on Ubuntu (22.04) was: