Page 1 of 1
'No module named tkinter' error when running file
Posted: Tue Mar 27, 2018 6:23 pm
by theMusicMan
Hello all
Just bought a nice new Raspberry Pi 3 and am very much enjoyuing busily running through loads of tutorials online etc. I am trying to run one such tutorial from here;
https://core-electronics.com.au/tutoria ... nners.html - specifically, the tutorial in Chapter 4.2
But, each time I run the file I get the following error;
Code: Select all
Traceback (most recent call last):
File "ledtoggle.py", line 3, in <module>
from tkinter import *
ImportError: No module named tkinter
Can anyone point me in the right direction please. From what I have read I thought tkinter was included as part of the defauls Raspberry install?
Many thanks.
John
Re: 'No module named tkinter' error when running file
Posted: Tue Mar 27, 2018 6:30 pm
by B.Goode
How, exactly, are you running the script?
tkinter is compatible only with Python3.
The equivalent for Python, which will default to Python2, is Tkinter.
Re: 'No module named tkinter' error when running file
Posted: Tue Mar 27, 2018 6:32 pm
by theMusicMan
Hi
Many many thanks for the very quick reply - much appreciated!
I am simply typing...
python ledtoggle.py
... at the prompt.
Not sure which version of Python I am running but I only installed everything today! How can I check this for you please?
Thanks
Re: 'No module named tkinter' error when running file
Posted: Tue Mar 27, 2018 6:38 pm
by B.Goode
Re: 'No module named tkinter' error when running file
Posted: Tue Mar 27, 2018 6:42 pm
by theMusicMan
Aha.... that did something different. Now getting this...
Code: Select all
Traceback (most recent call last):
File "ledtoggle.py", line 13, in <module>
win = Tk()
File "/usr/lib/python3.5/tkinter/__init__.py", line 1880, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
Hmmmm....
Re: 'No module named tkinter' error when running file
Posted: Tue Mar 27, 2018 6:48 pm
by B.Goode
Tell us more about how your system is set up. Have you booted into the Raspberry Pi Foundation Desktop, the one that defaults to a screensaver with a road heading for the sun?
You can't run graphical applications from a simple command-line login or with a Raspbian-lite OS installation.
Re: 'No module named tkinter' error when running file
Posted: Tue Mar 27, 2018 6:55 pm
by theMusicMan
You're a super star for replying so quickly, thank you very much.
I have the full Raspbian installed (which was done earlier today), no NOOBS option was presented to me when I first powered up the Pi3 so I selected the full install. Took about 15 mins.
Yep, I have that screen background image - well I did have it, until I changed it for an alternate
I have managed to get SSH sorted so I can access the Pi3 from my Mac, and I have also installed Windows Remote desktop as per another tutorial and can log into the Pi3 GUI from my Mac too, but I prefer not to do that at the moment and want to learn shell. If I need to access the GUI I do so on the spare TV I have the Pi3 connected to at the moment - it's waaaaay tooooo big though haha. Eventually need to buy a smaller monitor.
Ok, so I guess I am trying to run the graphical application in that tutorial form a command line... which might be another reason I am not having much success with it. How should I be running that GUI app?
Thanks again.
Re: 'No module named tkinter' error when running file
Posted: Tue Mar 27, 2018 7:11 pm
by B.Goode
I am trying to run the graphical application in that tutorial form a command line... which might be another reason I am not having much success with it.
That's the problem.
There are workarounds for running this from an ssh session, but I don't have time to write it up just now...
Do it from the GUI.
Re: 'No module named tkinter' error when running file
Posted: Tue Mar 27, 2018 7:19 pm
by theMusicMan
Ah, Okies. Will try so now. Thanks again for you help. Much appreciated.
Re: 'No module named tkinter' error when running file
Posted: Tue Mar 27, 2018 7:23 pm
by theMusicMan
B.Goode wrote: ↑Tue Mar 27, 2018 7:11 pm
I am trying to run the graphical application in that tutorial form a command line... which might be another reason I am not having much success with it.
That's the problem.
There are workarounds for running this from an ssh session, but I don't have time to write it up just now...
Do it from the GUI.
Aaaaand.... perfect! Runs perfectly. Once again thanks so very much.
Re: 'No module named tkinter' error when running file
Posted: Tue Mar 27, 2018 7:44 pm
by B.Goode
A good evening for both of us. Pleased you have made so much progress.
Re: 'No module named tkinter' error when running file
Posted: Tue Mar 27, 2018 7:53 pm
by theMusicMan
B.Goode wrote: ↑Tue Mar 27, 2018 7:44 pm
A good evening for both of us. Pleased you have made so much progress.
All in all, an excellent first day with the Raspberry Pi3! And much of it down to your help
I've done a little bit with the Arduino a year or so ago, but decided only yesterday to go for it and get a Pi3, and am so glad I did. I have plenty of projects in my '
I think I will have a go at that project' folder, though I am not sure I have enough time to get through them! One of which is a rather ambitious one... security type project, PIR sensing someone at door, camera taking pic, then somehow getting notice to my phone and allowing me to see the pic just taken et al.... we shall see!
Enjoy the rest of your evening...