0

I have the issue with Python 3.9.1 on freshly installed Ubuntu (Ubuntu 20.04.1 LTS) - when running any tkinter-based application, I get import error (example from python console):

user@ubuntu:~$ python3
Python 3.9.1 (default, Dec 29 2020, 13:25:02) 
[GCC 5.4.0 20160609] 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 "/home/linuxbrew/.linuxbrew/Cellar/python@3.9/3.9.1_3/lib/python3.9/tkinter/__init__.py", line 37, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'

I know this issue was discussed multiple times in SO and other internet resources, for several days I am trying all the options and solutions (like this, this, another one, brew forum neither of them solved the issue).
What works - only uninstalling homebrew does the trick. Still have hope to configure everything to work with homebrew.

What I have tried/performed:

  • fixed all brew doctor reported issues:
Your system is ready to brew.
  • tcl-tk is listed under brew list:
black  hello             libx11  libxdmcp  openssl@1.1  pylint      sqlite  xorgproto
bzip2  libffi            libxau  libxext   patchelf     python@3.9  tcl-tk  xz
gdbm   libpthread-stubs  libxcb  ncurses   pkg-config   readline    unzip   zlib
  • performed brew uninstall python and brew install python

  • Initial thought was poetry and/or pyenv broke the dependencies, currently using neither of them.

I am not hardcore ubuntu user, am I missing something? Any idea or help would be valuable.

Valdemort
  • 1
  • 2

2 Answers2

0

Homebrew is not the official pcakage mamanger for ubuntu and has some strange behaviours ,Ubuntu's officialy supported pacakage manager that is installed by default is apt(advanced package tool)

First uninstall your brew install of python by typing:

brew uninstall python

Then this is how you use APT to install python3:

sudo apt-get install python3

OR

sudo apt install python3

And to test if python3 installed correctly type:

python3

If a python shell opens python3 has been installed properly

Then to test if tkinter is working type this in the python shell:

import tkinter

TERMINATOR
  • 1,180
  • 1
  • 11
  • 24
  • Thanks, tried it all already, I confirm, this works. Still trying to figure out how to work it out with homebrew. – Valdemort Jan 04 '21 at 17:45
  • Any other ideas, or suggestions would be welcome – Valdemort Jan 04 '21 at 17:47
  • Update: @TERMINATOR, just in case tried all the steps you have provided: * unistalled the python on with brew uninstall * installed python3 on ubuntu - it was installed already... * ran python3 - it gives the error that cannot find python on homebrew path: "user@ubuntu:~$ python3 bash: /home/linuxbrew/.linuxbrew/bin/python3: No such file or directory" Maybe any issue with environmental variables. Unless I unistall brew completely it does not work. – Valdemort Jan 04 '21 at 17:55
0

Closing the question, as no other activity for over a week. Used solution I wanted to avoid - removed homebrew, now Tkinter is detected properly. For anyone stumbling on the same issue - uninstalling homebrew: https://github.com/homebrew/install#uninstall-homebrew

Valdemort
  • 1
  • 2