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
2 Answers 2
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– Tom Boddaert2019年10月05日 21:59:26 +00:00Commented Oct 5, 2019 at 21:59
-
Did you try uninstalling it, then reinstalling.Daniel– Daniel2019年10月12日 21:06:42 +00:00Commented Oct 12, 2019 at 21:06
-
Yes both tkinter and raspianTom Boddaert– Tom Boddaert2019年10月14日 06:52:14 +00:00Commented 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 filesls
Daniel– Daniel2019年10月19日 20:19:08 +00:00Commented Oct 19, 2019 at 20:19
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 errorTom Boddaert– Tom Boddaert2019年10月06日 08:50:14 +00:00Commented Oct 6, 2019 at 8:50
python3 -m tkinter
give you?