[Python] RHEL/Pyenv: No module named '_tkinter'

Discussão em 'Python' iniciado por Stack, Maio 9, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to use Matplotlib on RHEL using a pyenv installed version of python 3.6.5. (installed using the following command)

    → pyenv install 3.6.5

    Installing Python-3.6.5...
    python-build: use readline from homebrew
    Installed Python-3.6.5 to /home/swp1g17/.pyenv/versions/3.6.5
    → pyenv global 3.6.5


    I'm presented with the following error, and have found many questions that have a similar issue:

    Python 3.6.5 (default, Apr 5 2018, 17:22:36)
    [GCC 5.5.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import tkinter
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/home/swp1g17/.pyenv/versions/3.6.5/lib/python3.6/tkinter/__init__.py", line 36, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
    ModuleNotFoundError: No module named '_tkinter'


    However the suggested solution is usually to install tkinter using a package manager. However I've tried installing:

    2872 sudo yum install rh-python36-python-tkinter
    2873 sudo yum install rh-python35-python-tkinter
    2874 sudo yum install rh-python34-python-tkinter
    2891 sudo yum install tkinter
    2893 sudo yum install python36-tkinter
    2902 sudo yum install gcc zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel tk-devel gdbm-devel ncurses-devel gl..
    2916 sudo yum install tkinter.x86_64 rh-python36-python-tkinter.x86_64 rh-python35-python-tkinter.x86_64 rh-python34-python-tkinter.x86_64 p..
    2921 sudo yum install tcl
    2933 sudo yum install tk-devel
    2934 sudo yum install tk
    3000 sudo yum install tkinter
    3026 sudo yum install tix
    3031 sudo yum install tk
    3032 sudo yum install tk-devel
    > 3033 sudo yum install tcl-devel


    with each already having been installed or making no difference (having rebuilt python each time a new package was installed.

    The system python is able to locate tkinter:

    → /usr/bin/python3.6
    Python 3.6.3 (default, Jan 4 2018, 16:40:53)
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import tkinter
    >>>


    so I'm unsure how to install python using pyenv and have it use the same version of tkinter?


    UPDATE: Having found that build configuration options can be set using $PYTHON_CONFIGURE_OPTS I've tried specifying the library locations using (for linuxbrew downloaded tcl/tk):

    export PYTHON_CONFIGURE_OPTS="--with-tcltk-includes=-I/home/linuxbrew/.linuxbrew/opt/tcl-tk/include --with-tcltk-libs=-L/home/linuxbrew/.linuxbrew/opt/tcl-tk/lib"
    pyenv install 3.6.5


    and (using system tcl/tk):

    export PYTHON_CONFIGURE_OPTS="--with-tcltk-includes=-I/usr/include --with-tcltk-libs=-L/usr/lib64"
    pyenv install 3.6.5


    each with no luck. System tcl/tk was found using:

    → whereis tcl
    tcl: /usr/lib64/tcl8.5 /usr/include/tcl.h /usr/share/tcl8.5
    → whereis tcl
    tcl: /usr/lib64/tcl8.5 /usr/include/tcl.h /usr/share/tcl8.5

    Continue reading...

Compartilhe esta Página