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

让tkinter在带有asdf的macos上使用python 3.x,python,python-3.x,tkinter,Python,Python 3.x,Tkinter,所以我被难住了。如何让python 3.7.x与带有asdf的tkinter一起工作 我做了以下工作: 1) asdf本地python 3.7.4 2) brew安装tcl tk 3) brew链接tcl tk——强制执行 4) python-mvenv——系统站点包nltk 我有一些代码,比如: import nltk from nltk.corpus import wordnet as wn from tkinter import * # Let's get the first sense

所以我被难住了。如何让python 3.7.x与带有asdf的tkinter一起工作

我做了以下工作:

1)
asdf本地python 3.7.4

2)
brew安装tcl tk

3)
brew链接tcl tk——强制执行

4)
python-mvenv——系统站点包nltk

我有一些代码,比如:

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脚本来绘制概念树。我得到以下输出:

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'
回溯(最近一次呼叫最后一次):
文件“concept_tree.py”,第3行,在
从tkinter进口*
文件“/Users/alexander/.asdf/installs/python/3.7.4/lib/python3.7/tkinter/\uuuuu init\uuuuuuu.py”,第36行,在
导入_tkinter#如果失败,您的Python可能无法配置为Tk
ModuleNotFoundError:没有名为“\u tkinter”的模块

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

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

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安装python 3.7.4

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,则需要先卸载&reshim,然后再使用configure选项运行命令