0
votes

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?

2
Did you build Python 3.7 yourself? - acw1668
I think I just installed it using sudo apt install python3.7 - Z Gu
I can import tkinter in python 3.6.9. And I just can't install it to 3.7.3. What should I do? - Z Gu
Normally, using apt-get install python3.7 should install files to /usr/bin and /usr/lib. But your error message shows that the files are installed to /usr/local/bin and /usr/local/lib. It looks like it is installed from source. Try to reinstall python3.7 and python3-tk. python3-tk includes libraries for version 3.6 to 3.8. And you can execute dpkg-query -L python3-tk to show installed files. - acw1668

2 Answers

0
votes

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?

-1
votes

acw1668: Thanks this helped me a lot. I'm using Python 3.8. Using your method was able find where tkinter for Python 3.8 was install (/usr/lib/python3.8/). So i copied the files to (/usr/local/lib/python3.8/) which is where Python is installed on my computer. Now it'e working.