How do I link the ActiveState distribution of Tcl/Tk to HomeBrew installed Python
Asked Answered
A

3

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

Abbreviation answered 18/11, 2016 at 17:25 Comment(7)
Good question. Would love to know the answer.Tagmemic
you could try to import tcl and check its location, force PYTHONPATH to point on the new TCL installation whatever the command.Thrombin
Possibly try other StackExchange sites for issues with Homebrew and coding language OS compatibility.Seroka
Possible duplicate of Why my Python installed via home brew not include TkinterShang
@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.Abbreviation
@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?”Shang
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.Shang
S
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
Situated answered 21/1, 2017 at 1:41 Comment(3)
This solution worked. The IDLE error is gone and all is well--thanks!Apogamy
the option --with-tcl-tk no longer exists. What should I do now?Horeb
homebrew/dupes is now deprecated - the link above to the github repo no longer works. Try running just brew install tcl-tk.Wonderwork
L
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)

Leathaleather answered 20/1, 2017 at 13:44 Comment(4)
This option seems to error out: Error: No formulae found in taps.Apogamy
brew install python --with-tcl-tkLeathaleather
Run brew doctor there seems to be problem with homebrew installationLeathaleather
@Apogamy 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!Situated
I
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

Intervene answered 9/1, 2017 at 6:0 Comment(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 #11948795Simonetta

© 2022 - 2024 — McMap. All rights reserved.