Why my Python installed via home brew not include Tkinter
I am running MacOS Big Sur (11.2.3).
With python2, I have Tkinter
built-in.
With python3, it has to be installed manually and it's very simple, just run:
$ brew install python-tk
To run python2 in a terminal, execute python file.py
.
To run python3 in a terminal, execute python3 file.py
.
Based on the comments from above and the fact that Python must be linked to Tcl/Tk framework:
If you don't have Xcode command line tools, install those:
xcode-select --install
If you don't have Tcl/Tk brew installation (check brew list), install that:
brew install tcl-tk
Then, run "brew uninstall python" if that was not installed with option --with-tcl-tk (the current official option). Then install Python again, linking it to the brew installed Tcl/Tk:
brew install python --with-tcl-tk
12/18 Update: No longer possible for various reasons.
Below is now outdated. You'll have to install Python directly from python.org if you want to remove those warnings.
2018 Update
brew reinstall python --with-tcl-tk
Note: Homebrew now uses Python 3 by default - Homebrew Blog. Docs.
Testing
python
should bring up system’s Python 2, python3
should bring up Python 3.
idle
points to system Python/tcl-tk. It will show an out-dated tcl-tk error (unless you brew install python@2 --with-tcl-tk
)
idle3
should bring up Python 3 with no warnings.
Caveat
--with-tcl-tk
will install python
directly from python.org, which you'll see when you run brew info python
.
More info here.