使用virtualenv修复Mac上的Python 3 tkinter问题 [英] Fixing Python 3 tkinter issues on Mac with a virtualenv

查看:175
本文介绍了使用virtualenv修复Mac上的Python 3 tkinter问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

认为的简短问题是:如何获得运行Python 3.5的virtualenv指向Mac上正确的ActiveTcl版本?

I think the short version of this question is: How do I get a virtualenv running Python 3.5 to point to the correct version of ActiveTcl on a Mac?

这是更长的版本:

我正在尝试在Mac上运行此Korg Electribe示例编辑器项目.作者仅在Windows上对其进行了测试,并且基于屏幕截图,它似乎可以正常工作.我已经能够很好地运行基本的python脚本,但是在我提到的一个问题中已经打开,加载文件后,整个窗口会变黑.

I'm trying to run this Korg Electribe sample editor project on a Mac. The author has only tested it on Windows, and based on the screenshots, it appears to work. I've been able to run the basic python script fine, but as I mention in an issue that I've opened, the full window turns black after loading a file.

经过一些研究,我发现Aqua可可Tk有一个已知问题 ,并且python.org 提供了一些有关如何修复tkinter的说明 Mac OS 10.9及更高版本.我尝试安装建议的ActiveTcl(8.5.18.0)和较新的8.6.x.x版本,但均未成功.

After doing some research, I've found that there is a known issue with Aqua Cocoa Tk, and python.org has provided some instrunctions about how to fix tkinter for Mac OS 10.9 and up. I've attempted installing both of the suggested ActiveTcl (8.5.18.0) as well as the newer 8.6.x.x version without success.

我非常确定这是与 Tkinter无法正常工作的Mac不同的问题osx el capitan ,因为脚本确实在运行,并且在启动时正确绘制了窗口.只有在我尝试加载.all文件(Github问题中有一个示例文件)之后,屏幕才变黑.

I'm pretty sure this is a different issue than Tkinter not working mac osx el capitan, since the script does run, and the window is drawn properly on launch. It's only after I've attempted to load a .all file (there's a sample file in the Github issue) that the screen goes black.

经过更多研究,我发现此问题似乎相关,但特定于Windows: Virtualenv中的TKinter

After some more research, I've found this question that seems related, but is specific to Windows: TKinter in a Virtualenv

我的印象是,如果我能弄清楚将TCL_LIBRARY设置为什么,我将能够取得一些进展,但是我似乎找不到列出的软件包的信息.在python.org上.

I'm under the impression that if I can figure out what to set TCL_LIBRARY to, that I'll be able to make some head-way, but I can't seem to find that information for the packages listed on python.org.

有些相关,如果我能从Python内找出指向哪个版本的Tcl/Tk ,这似乎也很有帮助,所以如果有人可以提供帮助,好吧,我将不胜感激.

Somewhat related, it would also seem to be helpful if I could figure out which version of Tcl/Tk that tkinter is pointing to from within Python, so if anyone could help with that as well, I'd greatly appreciate it.

谢谢!

推荐答案

我通过以下方法成功在OSX 10.13的python3 virtualenv中使用tkinter:

I succeeded in using tkinter in a python3 virtualenv on OSX 10.13 by :

  • installing the official OSX Python 3 from https://www.python.org/
  • installing activeTcl from https://www.activestate.com/activetcl
  • creating a new virtualenv

mkvirtualenv myenv --python=python3

  • 在Python3目录中找到tkinter的位置.对我来说是在这里:

  • locating the tkinter location in the Python3 directory. For me it was here :

    /usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter
    

  • 在virtualenv库中创建指向tkinter位置的符号链接

  • creating a symbolic link in the virtualenv library pointing to the tkinter location

    cd ~/.virtualenvs/myenv/lib/python3.6
    ln -s /usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter tkinter
    

  • 这篇关于使用virtualenv修复Mac上的Python 3 tkinter问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆