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

Community
  • 1
  • 1
Tom Burrows
  • 1,944
  • 1
  • 27
  • 41
  • 1
    Good question. Would love to know the answer. – clearlight Jan 08 '17 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. – Jean-François Fabre Jan 08 '17 at 20:30
  • Possibly try [other StackExchange sites](http://stackexchange.com/sites) for issues with Homebrew and coding language OS compatibility. –  Jan 16 '17 at 18:23
  • Possible duplicate of [Why my Python installed via home brew not include Tkinter](https://stackoverflow.com/questions/36760839/why-my-python-installed-via-home-brew-not-include-tkinter) – JBallin Feb 13 '18 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. – Tom Burrows Feb 14 '18 at 09:39
  • @tburrows13 I agree they don’t seem the same but IMO they’re both asking “How do I link the updated TCL/TK to Homebrew’s Python?” – JBallin Feb 14 '18 at 16:52
  • Note that I found both when I had this problem and I finally figured it out. My answer on this one was deleted as a duplicate but I made some changes and voted to bring it back. – JBallin Feb 14 '18 at 16:57

3 Answers3

2

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
fedepad
  • 4,229
  • 1
  • 9
  • 24
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)

Sarvex
  • 733
  • 2
  • 6
  • 17
  • This option seems to error out: `Error: No formulae found in taps.` – Borealis Jan 20 '17 at 14:05
  • `brew install python --with-tcl-tk` – Sarvex Jan 20 '17 at 14:08
  • Run `brew doctor` there seems to be problem with homebrew installation – Sarvex Jan 20 '17 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 Jan 21 '17 at 01: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

Illusionist
  • 4,274
  • 7
  • 38
  • 60
  • 1
    The above solution did not work for me. You may have to recompile Python with path to TCL. You may find some additional details at http://stackoverflow.com/questions/11948295/install-tkinter-and-python-locally – Sharad Jan 09 '17 at 06:15