Uncategorized

tkinter and linux newbie sorrow

    • @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 2 days ago    
    • @Milliways Thank you, I have updated the post to elaborate. – Tom Boddaert yesterday
    • @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 13 hours ago
  • @Tom Boddaert, First of all, let me confess that I am a Windows guy and hate to use the less linux terminal commands I know how to use. I used to tell me sad story that not too many years ago I followed the instructions to install a software package, using “wget”, “tar”, “make” etc. It was the first time I heard of “wget”, and I didn’t know how to use Windows to unzip “tar” files. I also did not know about why some “local” files must use “./” in front of the file name, and there are “aliases” which are “nick names” where you cannot find the directory, … – tlfong01 12 hours ago   
  • Fast forward to a year ago, when I was using Rpi3B+ and Python 3.7.3. I needed to upgrade to python 3.7.4 for a tensorFlow package. If I remember correctly, I first use pip (or pip3, I forgot, because I did not know pip and pip3 are different, and might install the package in different directories for python2 or python3 (at that time I think there are python2 and python3 in different directories, and if your run python2 or python3 programs, you must use “sudo pyton2 myprogram” and “sudo python3 myprogram”, … – tlfong01 12 hours ago   
  • I did not know that my bash command sees “python2” or “python3” as a bash command to run a “script” which is actually the python program “script” the first line of which is a “comment” which tells bash guy which python2 or python3 “environment”, containing relevant modules to import, must go to before start running the program. Anyway, back to point where I was upgrading from python 3.7.3 to 3.7.4. The instruction actually tells me to set up an “environment” (the first time I heard this name). Anyway, my installed package could not start (cannot find module to import, or something) … – tlfong01 12 hours ago   
  • I did not know where I did wrong when using pip. So I used another install tool call “npm” or something to install python 3.7.4. But no luck again. Then I used another installation tools call “cell..” (forgot exact name). Then one more installation package (forgot name). Every time I used a new raspbian jessie/stretch image (I have 50+ micro SD cards in my card holder). At last I concluded that perhaps I missed something import (like there should be no space before the “=” symbol in a statement). But I could not find where the installed python3 programs stays (still don’t know “aliases”) – tlfong01 12 hours ago   
  • So I gave up, after struggling for perhaps 5 hours, and decided to come back when Rpi4B arrives. Now I have Rpi4B, buster, and Thonny. IDLE as gone, but I can also use Geany. Thank you for reading my long sad story. Now the thing you might find useful: (1) I found some program which can run in Thonny CANNOT run in Geany, (2) Other guys complain that they could not run their python program but I could run in Thonny, but not in Geany. So Thonny is my best friend. – tlfong01 12 hours ago   
  • One more case (not sure if I guess correctly) is that one guy uses HAT which Rpi talks to the HAT when booting and setup some config. The guy cannot run in terminal mode, but I am run in Thonny, but not in Geany. I told you my background in my introduction, because I need to warn you that I am make some guesses which might be wrong and lead you to a dark alley, … This is the end of my story. In case I remember more relevant things, I would tell you later. Good luck and cheers. – tlfong01 12 hours ago   
  • PS – In case your are curious, I am writing my story for two reasons: (1) To look back my failures and see if I can find a pattern to use for the future, (2) To practise my use of English. – End of my story – – tlfong01 12 hours ago   

Tkinter not running on updated python

Asked 
Active today
Viewed 29 times
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
 New contributor
  • 1
    Is tkinter installed? What does python3 -m tkinter give you? – Dougie 2 days ago
  • Your problem is probably caused by so I updated it to 3.7.4. How? – Milliways 2 days ago
  • @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 2 days ago    
  • @Milliways Thank you, I have updated the post to elaborate. – Tom Boddaert yesterday
  • @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 13 hours ago
  • @Tom Boddaert, First of all, let me confess that I am a Windows guy and hate to use the less linux terminal commands I know how to use. I used to tell me sad story that not too many years ago I followed the instructions to install a software package, using “wget”, “tar”, “make” etc. It was the first time I heard of “wget”, and I didn’t know how to use Windows to unzip “tar” files. I also did not know about why some “local” files must use “./” in front of the file name, and there are “aliases” which are “nick names” where you cannot find the directory, … – tlfong01 12 hours ago   
  • Fast forward to a year ago, when I was using Rpi3B+ and Python 3.7.3. I needed to upgrade to python 3.7.4 for a tensorFlow package. If I remember correctly, I first use pip (or pip3, I forgot, because I did not know pip and pip3 are different, and might install the package in different directories for python2 or python3 (at that time I think there are python2 and python3 in different directories, and if your run python2 or python3 programs, you must use “sudo pyton2 myprogram” and “sudo python3 myprogram”, … – tlfong01 12 hours ago   
  • I did not know that my bash command sees “python2” or “python3” as a bash command to run a “script” which is actually the python program “script” the first line of which is a “comment” which tells bash guy which python2 or python3 “environment”, containing relevant modules to import, must go to before start running the program. Anyway, back to point where I was upgrading from python 3.7.3 to 3.7.4. The instruction actually tells me to set up an “environment” (the first time I heard this name). Anyway, my installed package could not start (cannot find module to import, or something) … – tlfong01 12 hours ago   
  • I did not know where I did wrong when using pip. So I used another install tool call “npm” or something to install python 3.7.4. But no luck again. Then I used another installation tools call “cell..” (forgot exact name). Then one more installation package (forgot name). Every time I used a new raspbian jessie/stretch image (I have 50+ micro SD cards in my card holder). At last I concluded that perhaps I missed something import (like there should be no space before the “=” symbol in a statement). But I could not find where the installed python3 programs stays (still don’t know “aliases”) – tlfong01 12 hours ago   
  • So I gave up, after struggling for perhaps 5 hours, and decided to come back when Rpi4B arrives. Now I have Rpi4B, buster, and Thonny. IDLE as gone, but I can also use Geany. Thank you for reading my long sad story. Now the thing you might find useful: (1) I found some program which can run in Thonny CANNOT run in Geany, (2) Other guys complain that they could not run their python program but I could run in Thonny, but not in Geany. So Thonny is my best friend. – tlfong01 12 hours ago   
  • One more case (not sure if I guess correctly) is that one guy uses HAT which Rpi talks to the HAT when booting and setup some config. The guy cannot run in terminal mode, but I am run in Thonny, but not in Geany. I told you my background in my introduction, because I need to warn you that I am make some guesses which might be wrong and lead you to a dark alley, … This is the end of my story. In case I remember more relevant things, I would tell you later. Good luck and cheers. – tlfong01 12 hours ago   
  • PS – In case your are curious, I am writing my story for two reasons: (1) To look back my failures and see if I can find a pattern to use for the future, (2) To practise my use of English. – End of my story – – tlfong01 12 hours ago   

2 Answers

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 2 days ago

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 yesterday

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: