1

So, I'm trying to use a project, that uses tkinter on my Raspberry Pi but I have an issue. I needed an updated version of Python, so I updated it to 3.7.4, however, when I try to import tkinter, it gives me the error message ModuleNotFoundError: No module named '_tkinter'. Tkinter also gives the message If this fails, your Python may not be configured for Tk. Other modules import as usual. How can I configure Python to use Tk? Thank you, in advance, for any help.

python3 -m tkinter gives the same error message as trying to import it. I tried sudo apt-get install python-tk and sudo apt-get install python3-tk but it says it's already the latest version and doesn't do anything. I then uninstalled and reinstalled tkinter but that didn't help.

I updated Python by running these commands (I have wiped the system and done it again, but same issue):

cd ~
wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
tar -zxvf Python-3.7.4.tgz
cd Python-3.7.4
./configure
make
sudo make install
  • 1
    Is tkinter installed? What does python3 -m tkinter give you? – Dougie Oct 5 at 18:58
  • Your problem is probably caused by so I updated it to 3.7.4. How? – Milliways Oct 6 at 0:29
  • @Tom Boddaert, I am using Rpi4B buster release 2019sep26 Thonny 3.2 python 3.7.3 (/usr/bin/python3). I tried this: >>> import tkinter returns >>>. Your problem is NOT specific to tkinter. PS - I have not installed tkinter beforehand. – tlfong01 Oct 6 at 1:00
  • @Milliways Thank you, I have updated the post to elaborate. – Tom Boddaert Oct 6 at 8:57
  • @tlfong01 Thank you for the suggestion but can you please elaborate on what you mean by it's not specific to tkinter, all other modules that don't use tkinter, that I have tried, work. – Tom Boddaert Oct 7 at 11:49
1


Check to see if it is installed use the terminal as Dougie stated in the comments.


If it's not installed type in the terminal
sudo apt-get install python3-tk


Testing in python shell
>>>import tkinter
>>>tkinter._test()

  • Thank you for the suggestion but it just says that it's already the latest version and doesn't do anything but"python3 -m tkinter" produces the same error as trying to import it. – Tom Boddaert Oct 5 at 21:59
  • Did you try uninstalling it, then reinstalling. – Daniel Oct 12 at 21:06
  • Yes both tkinter and raspian – Tom Boddaert Oct 14 at 6:52
  • Check to see if it's placing the library in the right folder. In Terminal cd /usr/local/lib/python3.7 Then list the files ls – Daniel Oct 19 at 20:19
1

python -m tkinter quite correctly reports No module named tkinter because the Python2 version is Tkinter

python -m Tkinter should work!

There is no need to install tkinter, because it should be included in python3.

  • Sorry, I missed the 3, I did run "python3 -m tkinter" and got an error – Tom Boddaert Oct 6 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.