首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >让tkinter在带有asdf的macos上使用python 3.x

让tkinter在带有asdf的macos上使用python 3.x
EN

Stack Overflow用户
提问于 2019-11-23 07:55:39
回答 1查看 314关注 0票数 2

所以我被难住了。如何让python 3.7.x与asdf一起使用tkinter?

我做了以下工作:

1) asdf local python 3.7.4

2) brew install tcl-tk

3) brew link tcl-tk --force

4) python -m venv --system-site-packages nltk

我有一些代码,比如:

代码语言:javascript
复制
import nltk
from nltk.corpus import wordnet as wn
from tkinter import *

# Let's get the first sense of vehicle
vehicle = wn.synsets('vehicle')[0]
# Let's build a concept tree
t = nltk.Tree(vehicle.name(), children=[
    nltk.Tree(vehicle.hyponyms()[3].name(), children=[]),
    nltk.Tree(vehicle.hyponyms()[4].name(), children=[]),
    nltk.Tree(vehicle.hyponyms()[5].name(), children=[]),
    nltk.Tree(vehicle.hyponyms()[7].name(), children=[
        nltk.Tree(vehicle.hyponyms()[7].hyponyms()[1].name(), children=[]),
        nltk.Tree(vehicle.hyponyms()[7].hyponyms()[3].name(), children=[]),
        nltk.Tree(vehicle.hyponyms()[7].hyponyms()[4].name(), children=[]),
        nltk.Tree(vehicle.hyponyms()[7].hyponyms()[5].name(), children=[]), nltk.Tree(vehicle.hyponyms()[7].hyponyms()[6].name(), children=[]),
        ]),
    ])
t.draw()

然后,我使用nltk库运行包含上述代码的python脚本,以绘制一棵概念树。我得到以下输出:

代码语言:javascript
复制
Traceback (most recent call last):
  File "concept_tree.py", line 3, in <module>
    from tkinter import *
  File "/Users/alexander/.asdf/installs/python/3.7.4/lib/python3.7/tkinter/__init__.py", line 36, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
EN

回答 1

Stack Overflow用户

发布于 2020-01-22 22:17:51

asdf python在幕后使用pyenv,因此您可以使用所有相同的构建选项。

在pyenv中,您需要在install命令前加上以下内容,以便使用tkinter进行安装:

代码语言:javascript
复制
PYTHON_CONFIGURE_OPTS="--with-tcltk-includes='-I/usr/local/opt/tcl-tk/include' --with-tcltk-libs='-L/usr/local/opt/tcl-tk/lib -ltcl8.6 -ltk8.6'"

这也可以放在asdf install python 3.7.4前面。

代码语言:javascript
复制
PYTHON_CONFIGURE_OPTS="--with-tcltk-includes='-I/usr/local/opt/tcl-tk/include' --with-tcltk-libs='-L/usr/local/opt/tcl-tk/lib -ltcl8.6 -ltk8.6'" asdf install python 3.7.4

请注意,这需要在全新安装python时完成。如果您已经安装了python,那么在运行带有configure选项的命令之前,您需要先卸载& reshim。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59003269

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档