10

Currently using Ubuntu 20.04 LTS with python3.8.5. Its my first time using ubuntu with absolutely no previous knowledge of terminal.SO,would love to have a detailed answer if possible. Below is terminal output when i try importing tkinter in python3.

>>> 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'
>>> 

I have reinstalled python3 and tkinter using sudo apt.But still it shows same error. When i run the same command in python IDLE it works without any error. I hope this explains my problem clearly, if any other info. is required pls reply. I also tried running the command >>>from tkinter import *

Atharva Dhamale
  • 151
  • 1
  • 2
  • 9
  • Try doing: sudo apt-get install python3-tk – Gautamrk Aug 29 '20 at 05:23
  • Thanks, but i have already installed it with the same command and when i try running the command again it shows that i already have the latest version of it – Atharva Dhamale Aug 29 '20 at 05:26
  • 1
    If you built python 3.8 from source you may need to recompile it. Be sure to check the output of the `configure` script for messages about which modules it cannot install. – snakecharmerb Aug 29 '20 at 05:31
  • @snakecharmerb i used make command to rebuild the install yet i am getting same error – Atharva Dhamale Aug 29 '20 at 06:51
  • Maybe you could install tkinter with `pip install tkinter` (or pip3). Maybe you have already installed pip while installing python, if not, just run `sudo apt-get install python3-pip` – Eric Roy Aug 29 '20 at 08:00
  • @EricRoy the command 'pip3 install tkinter' gave this WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. – Atharva Dhamale Aug 29 '20 at 09:13
  • @EricRoy the command 'sudo apt-get install python3-pip' gave this output **python3-pip is already the newest version (20.0.2-5ubuntu1).** – Atharva Dhamale Aug 29 '20 at 09:14
  • This may help you, in this case: https://stackoverflow.com/questions/45954528/pip-is-configured-with-locations-that-require-tls-ssl-however-the-ssl-module-in – Eric Roy Aug 30 '20 at 11:45

5 Answers5

8

I faced the same issue on MacOS. I was using a Python virtual environment. This command worked for me:

brew install python-tk
Woody1193
  • 7,252
  • 5
  • 40
  • 90
A.Ranjan
  • 119
  • 1
  • 2
  • 12
2

CentOS 8 + Python 3.9.5 following are what i have done:

1st:

yum search tkinter
yum install python39-tkinter.x86_64

2nd:

yum install tk-devel

3rd: cd python3.9.5 source folder

make install

it work in my case

Higer2019
  • 21
  • 3
2

since I'm still using python 3.9, this code works for me:

brew install python-tk@3.9

if using brew install python-tk brew will install python-tk@3.10 which is key-only

Ann
  • 103
  • 2
  • 4
0

I had the same issue. Switched from 3.8 to 3.7 and it worked. I'm using PyCharm CE, which makes it easy to switch between interpreters.

Daniel
  • 1
  • 2
0

Resolved the issue it occurred because the Tkinter was installed for version 3.5 and not for the 3.8 version. For that, I installed the 3.5 version and kept only one version i.e. 3.8, and installed Tkinter again, and it worked! This is just a workaround to make things work, but the more preferred way is to create a venv and then install the particular versions of python and libraries that are needed.

Atharva Dhamale
  • 151
  • 1
  • 2
  • 9