Hello thank you for taking a look at my question here.
I am new to coding and am learning python. I am using Linux, specifically Ubuntu. I wrote a simple tkinter-based application which when launched displays a countdown to a particular date and then has a button to click to close the window. I have run this application in PyCharm and it works perfectly there. I also runs perfectly in IDLE. in both, tkinter imports and runs just fine.
I located the .py file for my aplication in the terminal and used
$ chmod +x main.py
then
$ ./main.py
I get the response
ubuntu@ubuntu:~$ ./main.py
Traceback (most recent call last):
File "./main.py", line 9, in <module>
import tkinter
File "/usr/local/lib/python3.8/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
Most similar questions I have managed to find suggest that tkinter must be installed, but certainly it would appear that tkinter IS installed, it ran in PyCharm and in IDLE, I have followed the directories listed to see that they are in fact on the system, I have run
ubuntu@ubuntu:~$ pip install tk Defaulting to user installation because normal site-packages is not writeable Requirement already satisfied: tk in ./.local/lib/python3.8/site-packages (0.1.0)
I have run
ubuntu@ubuntu:~$ python3
Python 3.8.5 (default, Feb 4 2021, 18:26:47)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
everything I do seems to comfirm tkinter is installed yet will not import in Terminal. Any help?
update First of all I want to thank everyone who has commented so far, your insights have certainly led me to progress here.
I have discovered that I have 2 seperate installations of python 3.8.5
I showed above what happened when I used $python3 and >>>import tkinter in terminal. I just now tried calling the other installation in terminal by it's file path and issuing the same command:
root@ubuntu:/# /usr/bin/python3.8 Python 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter >>> exit()
tkinter imports. I do not get the above error.
I knew I had to have a working tkinter somewhere on my system because PyCharm and IDLE both successfully ran it. terminal however, still fails to import it when I simply attempt to run the .py file.
So now I suppose that my issue becomes how do I remove the Feb 4 installation and keep the Jul 28 installation, or how do I get the Feb 4 installation to import tkinter.
pip install tkinstallsTensorKit, nottkinter. You need to install via system package manager:sudo apt-get install python3-tk. - acw1668pythonpath? - pavelpythonpathis one of environmental variables that lives on your system and contains locations of directories where Python packages are installed. - pavel