1

On Raspbian, Buster, (Pi HW 4B) built and installed Pyton 3.11.1 Following tkinter docs (https://docs.python.org/3/library/tkinter.html) on first line of python program wrote:

from tkinter import *

received the following error: ModuleNotFoundError: No module name '_tkinter'

Following on numerous posts did the following using command line stmts:

pi@TBlank-Raspberry2:\~ $** python3 -V
Python 3.11.1

pi@TBlank-Raspberry2:\~ $** sudo apt-get install python3-tk
Reading package lists... Done
Building dependency tree  
Reading state information... Done
python3-tk is already the newest version (3.7.3-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

pi@TBlank-Raspberry2:\~ $** python3 -m tkinter
`Traceback (most recent call last):   
File "<frozen runpy>", line 189, in _run_module_as_main   
File "<frozen runpy>", line 148, in _get_module_details   
File "<frozen runpy>", line 112, in _get_module_details   
File "/usr/local/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'`

pi@TBlank-Raspberry2:\~ $

I've also found that using the python 3.10.9 compiler throws the same error.

All suggestions greatly appreciated. (hope first post wasn't too weak)

tblank1024
  • 11
  • 3

1 Answers1

1

I also had this issue, and was able to solve it by roughly following the steps here (I personally didn't uninstall my current Python installation, but it probably wouldn't hurt if you did). In summary, I was able to fix the issue by:

  1. Installing the tk-dev package: sudo apt install tk-dev
  2. Downloading Python again from https://www.python.org/downloads/source/. You shouldn't need to do this if you still have the source files from when you installed Python 3.11.1, unless you want to upgrade to the latest version.
  3. Changing into the Python source directory after unzipping it and then running sudo chmod +x configure, ./configure, make, and finally sudo make install.

Following this process, I was able to successfully import Tkinter:

>>> import tkinter
>>> tkinter.Tk()

An empty Tkinter window appears, as expected.

Quasquith
  • 11
  • 3