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
asked Oct 5, 2019 at 18:38
13
  • 1
    Is tkinter installed? What does python3 -m tkinter give you? Commented Oct 5, 2019 at 18:58
  • Your problem is probably caused by so I updated it to 3.7.4. How? Commented Oct 6, 2019 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. Commented Oct 6, 2019 at 1:00
  • @Milliways Thank you, I have updated the post to elaborate. Commented Oct 6, 2019 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. Commented Oct 7, 2019 at 11:49

2 Answers 2

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()

answered Oct 5, 2019 at 20:29
4
  • 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. Commented Oct 5, 2019 at 21:59
  • Did you try uninstalling it, then reinstalling. Commented Oct 12, 2019 at 21:06
  • Yes both tkinter and raspian Commented Oct 14, 2019 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 Commented Oct 19, 2019 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.

answered Oct 6, 2019 at 0:29
1
  • Sorry, I missed the 3, I did run "python3 -m tkinter" and got an error Commented Oct 6, 2019 at 8:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.