简体   繁体   English

如何将Tcl / Tk的ActiveState分发链接到HomeBrew安装的Python

[英]How do I link the ActiveState distribution of Tcl/Tk to HomeBrew installed Python

I am using macOS 10.12.1 Sierra. 我正在使用macOS 10.12.1 Sierra。 I am using Python 2.7.12 installed with 我使用的是Python 2.7.12

brew install python

but the IDLE gives the warning 但是IDLE给出了警告

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. 8.5.9是macOS预安装版本。

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). 我可以从ActiveState网站下载稳定的8.5.18(由python推荐,它与python.org的python安装一起工作(因为他们在使用不稳定的macOS默认8.5.9之前寻找任何其他版本的Tcl / Tk) )。

However this download does not affect the brew installed python IDLE, which continues to use 8.5.9. 但是这个下载不会影响brew安装的python IDLE,它继续使用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? 有什么我可以做的事情来链接更新的Tcl / Tk和Homebrew,或者我可以直接用自制软件安装Tcl / Tk吗?

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 我也注意到使用anaconda python时会出现完全相同的问题,它使用预安装的mac tcl / tk 8.5.9,而不是用户安装的tcl / tk 8.5.18。

tcl-tk can be installed via Homebrew and one can have the Homebrew installed python linked to that version (Homebrew installed) of tcl-tk . tcl-tk可以通过Homebrew安装,并且可以将Homebrew安装的python链接到tcl-tk该版本(Homebrew安装)。
The only " barrier " to that, is to enable the right homebrew tap , as tcl-tk is not found in the "default" taps in Homebrew. 唯一的“ 屏障 ”来表示,是为了让右自制的龙头tcl-tk未在“默认”水龙头在家酿找到。
Indeed tcl-tk is found in the tap called homebrew-dupes which contain (cite the page) 事实上tcl-tk是在名为homebrew-dupes的tap中找到的,其中包含(引用页面)

formulae that duplicate software provided by macOS, though may provide more recent or bugfix versions. 复制由macOS提供的软件的公式,但可能提供更新的或bugfix版本。

Here the link to homebrew-dupes: 这里是homebrew-dupes的链接:
https://github.com/Homebrew/homebrew-dupes https://github.com/Homebrew/homebrew-dupes
and here the formula for tcl-tk 这里是tcl-tk的公式
https://github.com/Homebrew/homebrew-dupes/blob/master/tcl-tk.rb 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 激活/安装homebrew-dupes tap
  2. Install tcl-tk 安装tcl-tk
  3. Install homebrew python using homebrew tcl-tk 使用自制软件tcl-tk安装自制软件python

The commands to be executed follow: 要执行的命令如下:

  1. brew tap homebrew/dupes
  2. brew install tcl-tk
  3. brew install python --with-tcl-tk

Homebrew is an excellent package manager and while installing any package it is recommended to see the info. Homebrew是一个优秀的包管理器,在安装任何包时,建议查看信息。

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) 使用Homebrew的Tk而不是macOS Tk(具有可选的Cocoa和线程支持)

I can think of a couple of messy solutions - 我可以想到几个凌乱的解决方案 -

1) Insert the actual location of the installed module at the beginning of the path 1)在路径的开头插入已安装模块的实际位置

import sys

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

2) Append the new location and remove the previous location 2)附加新位置并删除以前的位置

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 3)在bash中设置PYTHONPATH环境变量,并确保它没有损坏的位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM