DEPRECATION WARNING: The system version of Tk is deprecated, M1 Mac in Vs Code - global Python [duplicate]
Asked Answered
L

2

10

(M1 MBA 2020, MacOS 12.3.1) So inside of Vs Code, when I select my interpreter as Python 3.8.9 from my usr/local/bin Tkinter it runs as I want it to.

This is the working interpreter

Here is the running code for reference.

Running Code

The problem arises when I am trying to use the Global Python 3.8.9 interpreter (usr/bin/python3). When the code runs, the application ends up looking like this.

not working tkinter

Additionally, when I run the code the terminal reads the following:

DEPRECATION WARNING: The system version of Tk is deprecated and may be removed in a future release. Please don't rely on it. Set TK_SILENCE_DEPRECATION=1 to suppress this warning.

How is it possible for me to fix this error? Or update my global Tkinter version without straying away from Python 3.8.9. Furthermore if any more info is needed I'll be happy to provide, sorry I'm new to this stuff πŸ˜…

Packages used in the app: tkinter, Pillow, tkmacosx

One last thing, when I get rid of all mentions of the package Tkmacosx, the app appears like this:

app without tkmacosx

Libertylibia answered 2/6, 2022 at 7:19 Comment(2)
Maybe you could have a look at apple.stackexchange.com/a/315121 – Choragus
Did you install python directly from python.org ? – Choragus
C
15

If you have Homebrew installed, you can update tk with:

brew uninstall tcl-tk --devel
brew install tcl-tk

Which is the recommended option

Then you may need to add export PATH="/usr/local/opt/tcl-tk/bin:$PATH" to your .zshrc file:

If you are using a zsh terminal:

Zsh tab

Use:

echo "# For tkinter 
export PATH=\"/usr/local/opt/tcl-tk/bin:\$PATH\"" >> ~/.zshrc
source ~/.zshrc

Or if you are using a bash terminal:

echo "# For tkinter 
export PATH=\"/usr/local/opt/tcl-tk/bin:\$PATH\"" >> ~/.bashrc
source ~/.bashrc

If the steps above didn't work, you may need to install another package (@goker):

brew install [email protected]

Homebrew

Reference

Python's offical tk upgrade docs

Choragus answered 2/6, 2022 at 7:46 Comment(6)
Thanks for the response, so when I tried to uninstall Tkinter it said "--devel" is not supported... Anyways ignoring the "--devel" part I followed your instructions and the update error still appears :( Additionally, tck-tk has been added to '/opt/homebrew/Cellar', now how can i "link" this into my global python interpreter? – Libertylibia
Maybe add the full path of your tck-tk bin files to your path, as shown in the answer, but with your path obviously. It would look something like export PATH="/opt/homebrew/Cellar/tcl-tk/bin:$PATH in your bash or zsh profiles. Try $ where tcl-tk – Choragus
@Libertylibia no worries :) did adding your new tcl-tk to path fix the issue? – Choragus
@FreddyMcloughlan thanks although I was simply pushing to a repo and my creds were borked. Dont know why it worked as I wasnt using Code. But thanks. – Gloria
tkinter is no longer included with this formula, but it is available separately: brew install [email protected] – Therontheropod
installing python after this worked for me. I use pyenv. – Duodenitis
S
9

Answer from Freddy below https://mcmap.net/q/1049974/-deprecation-warning-the-system-version-of-tk-is-deprecated-m1-mac-in-vs-code-global-python-duplicate worked.

(this note was to be a response to the answer)

I have python 3.10.6 installed via pyenv, pyenv installed via homebrew. (Uninstall with --devel does not work)

  • installing tcl-tk with homebrew and reinstalling python 3.10.6 with pyenv, makes the python installation use the homebrew version of tcl-tk and after this IDLE works fine.
% brew install tcl-tk
% pyenv install 3.10.6
% python
>>> import idlelib.idle
Stokowski answered 3/10, 2022 at 2:5 Comment(2)
Installing Python after tcl-tk did the trick! – Waxler
Likewise for me. Simply installing via brew install tcl-tk was not enough. After installing tcl-tk via brew I reinstalled python, also using pyenv, and everything worked as expected. – Menander

© 2022 - 2024 β€” McMap. All rights reserved.