Python – install tkinter for python 3.7.3 in Ubuntu 18.04

pythontkinterUbuntu

When I import tinker in python 3.7.3 on Ubuntu 18.04:

>>> import tkinter

I got:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/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'

Then I install tk using both of the following:

sudo apt-get install python3-tk

It didn't work.

I also did all the things in Tkinter module not found on Ubuntu, still didn't work.
I noticed that when I do:

sudo apt-get install python3.7-tk

It says:

Note, selecting 'python3-tk' instead of 'python3.7-tk'
python3-tk is already the newest version (3.6.9-1~18.04).

Is tk automatically installed under python 3.6.9? How can I fix this?

I also saw a solution from https://wiki.python.org/moin/TkInter:

If it fails with "No module named _tkinter", your Python configuration needs to be modified to include this module (which is an extension module implemented in C). Do not edit Modules/Setup (it is out of date). You may have to install Tcl and Tk (when using RPM, install the -devel RPMs as well) and/or edit the setup.py script to point to the right locations where Tcl/Tk is installed. If you install Tcl/Tk in the default locations, simply rerunning "make" should build the _tkinter extension.

Could someone explain to do how to do the steps mentioned in this paragraph?

Best Answer

OK. I think the problem is that the newest version of tkinter for Ubuntu 18.04 is "python3-tk_3.6.9-1~18.04_i386.deb". Now I found that tk for python3.7.3 is available for other systems(e.g. python3-tk_3.7.3-1_amd64.deb). Can I download and use these ones on my system?

Related Topic