25

I am using macOS 10.12.1 Sierra. I am using Python 2.7.12 installed with

brew install python

but the IDLE gives the warning

WARNING: The version of Tcl/Tk (8.5.9) in use may be unstable.
Visit http://www.python.org/download/mac/tcltk/ for current information.

and sure enough, it crashed frequently. 8.5.9 is the macOS preinstalled version.

I can download the stable 8.5.18 from the ActiveState website (as recommend by python, which works with the python installations from python.org (as they look for any other version of Tcl/Tk before resorting to the unstable macOS default 8.5.9).

However this download does not affect the brew installed python IDLE, which continues to use 8.5.9.

Is there anything I can do to link the updated Tcl/Tk with Homebrew, or can I install Tcl/Tk direct with homebrew?

I have also noticed that exactly the same problem happens when using anaconda python, which uses the preinstalled mac tcl/tk 8.5.9, not the user-installed tcl/tk 8.5.18

7
  • 1
    Good question. Would love to know the answer.
    – clearlight
    Commented Jan 8, 2017 at 20:04
  • 1
    you could try to import tcl and check its location, force PYTHONPATH to point on the new TCL installation whatever the command. Commented Jan 8, 2017 at 20:30
  • Possibly try other StackExchange sites for issues with Homebrew and coding language OS compatibility.
    – user4734394
    Commented Jan 16, 2017 at 18:23
  • Possible duplicate of Why my Python installed via home brew not include Tkinter
    – JBallin
    Commented Feb 13, 2018 at 17:52
  • @JBallin, I don't think that that is a duplicate. While they have very similar answers, the question is pretty different, this one is wanting to replace the default installation of Tcl/Tk, and the 'dupe' is wondering why the tkinter isn't working at all. There doesn't seem like there is much likelihood of someone with this problem finding that question. I may be wrong here though. Commented Feb 14, 2018 at 9:39

3 Answers 3

2
+100

tcl-tk can be installed via Homebrew and one can have the Homebrew installed python linked to that version (Homebrew installed) of tcl-tk.
The only "barrier" to that, is to enable the right homebrew tap, as tcl-tk is not found in the "default" taps in Homebrew.
Indeed tcl-tk is found in the tap called homebrew-dupes which contain (cite the page)

formulae that duplicate software provided by macOS, though may provide more recent or bugfix versions.

Here the link to homebrew-dupes:
https://github.com/Homebrew/homebrew-dupes
and here the formula for tcl-tk
https://github.com/Homebrew/homebrew-dupes/blob/master/tcl-tk.rb

So the complete recipe to solve the problem would be:

  1. Activate/Install the homebrew-dupes tap
  2. Install tcl-tk
  3. Install homebrew python using homebrew tcl-tk

The commands to be executed follow:

  1. brew tap homebrew/dupes
  2. brew install tcl-tk
  3. brew install python --with-tcl-tk
3
  • This solution worked. The IDLE error is gone and all is well--thanks!
    – Borealis
    Commented Jan 21, 2017 at 5:09
  • the option --with-tcl-tk no longer exists. What should I do now?
    – Ignat
    Commented Feb 7, 2019 at 22:42
  • homebrew/dupes is now deprecated - the link above to the github repo no longer works. Try running just brew install tcl-tk.
    – Peter W
    Commented Oct 7, 2019 at 3:55
1

Homebrew is an excellent package manager and while installing any package it is recommended to see the info.

brew info python

shows a lot of options that can be passed; but the most important one is

--with-tcl-tk

Use Homebrew's Tk instead of macOS Tk (has optional Cocoa and threads support)

4
  • This option seems to error out: Error: No formulae found in taps.
    – Borealis
    Commented Jan 20, 2017 at 14:05
  • brew install python --with-tcl-tk
    – Sarvex
    Commented Jan 20, 2017 at 14:08
  • Run brew doctor there seems to be problem with homebrew installation
    – Sarvex
    Commented Jan 20, 2017 at 14:23
  • @Borealis Nothing is wrong with the homebrew installation. The error seems clear. The problem is that the right tap is not enabled. Try to look at my answer, which should give the complete recipe if one doesn't have the tap that contains tcl-tk enabled. But I might be wrong since I'm not in your computer!
    – fedepad
    Commented Jan 21, 2017 at 1:48
0

I can think of a couple of messy solutions -

1) Insert the actual location of the installed module at the beginning of the path

import sys

sys.path.insert(1, 'YourTclLocation')

2) Append the new location and remove the previous location

import sys
sys.path.append('YourTCLLocation')
sys.path.remove('ProblemLocation')
import Tcl

3) Set PYTHONPATH environment variable in bash and make sure it doesn't have the broken location

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.