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.
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
How do I run the version of tkinter I brew installed instead of the system version?
python-tk@3.9: It's no longer possible to 'import tkinter' in a Python venv / virtualenv (but it works outside of virtualenv)
brew install python --with-brewed-tk fails to make _tkinter.so
python - How to install tkinter on M1 Mac - Stack Overflow
On MacOS 12.5 I have updated to the latest version of Python and pip and I just brew installed tkinter. When I do "python3 -m tkinter", I get the message: DEPRECATION WARNING: The system version of Tk is deprecated and may be removed in a future release. - and the window that launches is buggy.
It seems like the command above is not running the version of tkinter I just installed with brew.
Why is that and how do I get rid of this deprecated system version?
Or in general what is the real issue here?
Thanks very much
Here is step by step guide to make IDLE and tkinter work:
- install
tcl-tkwith Homebrew. In shell runbrew install tcl-tk - in shell run
echo 'export PATH="/usr/local/opt/tcl-tk/bin:$PATH"' >> ~/.zshrc - reload shell by quitting
Terminalapp or runsource ~/.zshrc - after reloaded check that
tck-tkis in$PATH. Runecho $PATH | grep --color=auto tcl-tk. As the result you should see your $PATH contents withtcl-tkhighlighted - now we run three commands from Homebrew's output from step #1
- in shell run
export LDFLAGS="-L/usr/local/opt/tcl-tk/lib" - in shell run
export CPPFLAGS="-I/usr/local/opt/tcl-tk/include" - in shell run
export PKG_CONFIG_PATH="/usr/local/opt/tcl-tk/lib/pkgconfig"
- in shell run
- if you have your Python version already installed with
pyenvthen uninstall it withpyenv uninstall <your python version>. E.g.pyenv uninstall 3.8.2 - set environment variable that will be used by
python-build. In shell runPYTHON_CONFIGURE_OPTS="--with-tcltk-includes='-I/usr/local/opt/tcl-tk/include' --with-tcltk-libs='-L/usr/local/opt/tcl-tk/lib -ltcl8.6 -ltk8.6'"Note: in future usetck-tkversion that actually installed with Homebrew. At the moment of posting8.6was the actual - finally install Python with
pyenvwithpyenv install <version>. E.g.pyenv install 3.8.2
Test
- in shell run
pyenv global <verion that you've just installed> - now check IDLE. In shell run
idle. You should see IDLE window without any warnings and "text printed in red".

- now check
tkinter. In shell runpython -m tkinter -c "tkinter._test()". You should see test window like on the image:

That's it!
My environment:
check this is something went wrong executing steps above:
- macOS Catalina
zsh(included in macOS Catalina) = "shell" above- Homebrew (installed with instructions from Homebrew official website)
pyenv(installed with Homebrew and PATH updated according topyenvofficial readme from GitHub)- Python
3.8.x-3.9.x(installed withpyenv install <version>command)
I never got this to work. I spent a ton of time on this page as well as a number of other sites, and tried everything. It seems that Homebrew Python and Tcl-Tk are at this time not out of the box the same version, and it's a common issue. What I did end up doing was to install both pyenv and anaconda side by side as per the excellent instructions of @Simba here, and using Anaconda my Tcl-Tk commands are working fine. Posting here so that others don't fall down this rabbit hole, or if they do and find a solution, it would be wonderful to know.
After a day of headache, this worked for me:
$ brew install python-tk
I've had the same issue:
ModuleNotFoundError: No module named 'tkinter'
After quite a while I finally realized that I needed to install the python-tk package. On Linux all I needed to do was sudo apt-get install python3-tk.