Getting tkinter to work with python 3.x on macos with asdf [duplicate]

2024/9/20 20:38:26

So I'm stumped. How do I get python 3.7.x working with tkinter with asdf?

I did the following:

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

I have some code like:

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()

Then I run the python script containing code above using the nltk library to draw a concept tree. I get the following output:

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'
Answer

asdf python uses pyenv under the hood, so you can use all the same build options.

In pyenv, you would need to prepend the install command with the following in order to install with tkinter:

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'"

This can also be prepended to asdf install 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

Note that this needs to be done on a fresh install of python. If you already have python installed, you will need to first uninstall & reshim before running the command with the configure opts.

https://en.xdnf.cn/q/72458.html

Related Q&A

Flask server sent events socket exception

I am thinking of using SSE to push new data to the client and using Flot(javascript charting library) display "live" updates. My server runs on python Flask framework and I have figured out h…

Pandas adding scalar value to numeric column?

Given a dataframe like thisImageId | Width | Height | lb0 | x0 | y0 | lb1 | x1 | y1 | lb2 | x2 | y2 0 abc | 200 | 500 | ijk | 115| 8 | zyx | 15 | 16 | www | 23 | 42 1 def | 300 | 800 …

Sklearn Pipeline all the input array dimensions for the concatenation axis must match exactly

import pandas as pd from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer from sklearn.pipeline import Pipeline from sklearn.svm import LinearSVC from sklearn.preprocessing impo…

Python Pandas read_excel returns empty Dataframe

Reading a simple xls returning empty dataframe, cant figure it out for the life of me:path = (c:/Users/Desktop/Stuff/Ready) files = os.listdir(path) print(files)files_xlsx = [f for f in files if f[-3:]…

Fill matrix with transposed version

I have a pairwise matrix:>>> ma b c d a 1.0 NaN NaN NaN b 0.5 1.0 NaN NaN c 0.6 0.0 1.0 NaN d 0.5 0.4 0.3 1.0I want to replace the NaN in the the top right with the same va…

Subclass of numpy ndarray doesnt work as expected

`Hello, everyone.I found there is a strange behavior when subclassing a ndarray.import numpy as npclass fooarray(np.ndarray):def __new__(cls, input_array, *args, **kwargs):obj = np.asarray(input_array)…

How to correctly load images asynchronously in PyQt5?

Im trying to figure out how to accomplish an async image load correctly, in PyQt Qlistview.My main widget consists of a Qlistview and a QLineEdit textbox. I have a database of actors which I query usin…

How to print results of Python ThreadPoolExecutor.map immediately?

I am running a function for several sets of iterables, returning a list of all results as soon as all processes are finished.def fct(variable1, variable2):# do an operation that does not necessarily ta…

Python dir equivalent in perl?

The dir command in Python 2.7.x lists all accessible symbols from a module. Is there an equivalent in Perl 5.x to list all accessible symbols from a package?

Entire JSON into One SQLite Field with Python

I have what is likely an easy question. Im trying to pull a JSON from an online source, and store it in a SQLite table. In addition to storing the data in a rich table, corresponding to the many fiel…