问题
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
回答1:
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:
- Activate/Install the homebrew-dupes tap
- Install tcl-tk
- Install homebrew python using homebrew tcl-tk
The commands to be executed follow:
brew tap homebrew/dupes
brew install tcl-tk
brew install python --with-tcl-tk
回答2:
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)
回答3:
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
来源:https://stackoverflow.com/questions/40682794/how-do-i-link-the-activestate-distribution-of-tcl-tk-to-homebrew-installed-pytho