asdf-community / asdf-python

Python plugin for the asdf version manager
https://github.com/asdf-vm/asdf
MIT License
643 stars 55 forks source link

No module named _tkinter with Python 3.11.x (Mac M2) #159

Closed fedeotaran closed 1 year ago

fedeotaran commented 1 year ago

Hi, I can't install python with tkinter correctly on MacOS 13.2.1 (M2).

I successfully installed the package with homebrew: brew install tcl-tk

No matter what I do whenever I install a version of Python 3.11.x it shows me the following error:

python-build 3.11.2 /Users/mitt/.asdf/installs/python/3.11.2
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.11.2.tar.xz...
-> https://www.python.org/ftp/python/3.11.2/Python-3.11.2.tar.xz
Installing Python-3.11.2...
python-build: use tcl-tk from homebrew
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/mitt/.asdf/installs/python/3.11.2/lib/python3.11/tkinter/__init__.py", line 38, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
    ^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named '_tkinter'
WARNING: The Python tkinter extension was not compiled and GUI subsystem has been detected. Missing the Tk toolkit?
Installed Python-3.11.2 to /Users/mitt/.asdf/installs/python/3.11.2

Installation commands I tried

asdf install python 3.11.2 asdf install python 3.11.2 --with-tcl-tk asdf install python 3.11.2 --with-tcltk-lib=/opt/homebrew/Cellar/tcl-tk/8.6.13_2/lib

env \
PATH="/opt/homebrew/Cellar/tcl-tk/8.6.13_2/bin:$PATH" \
LDFLAGS="-L/opt/homebrew/Cellar/tcl-tk/8.6.13_2/lib" \
CPPFLAGS="-I/opt/homebrew/Cellar/tcl-tk/8.6.13_2/include" \
PKG_CONFIG_PATH="/opt/homebrew/Cellar/tcl-tk/8.6.13_2/lib/pkgconfig" \
CFLAGS="-I/opt/homebrew/Cellar/tcl-tk/8.6.13_2/include" \
PYTHON_CONFIGURE_OPTS="--with-tcltk-includes='-I/opt/homebrew/Cellar/tcl-tk/8.6.13_2/include' --with-tcltk-libs='-L/opt/homebrew/Cellar/tcl-tk/8.6.13_2/lib -ltcl8.6 -ltk8.6'" \
asdf install python 3.11.2

I did it on my old mac and it works perfectly (MacBook Pro 2016).

Does anyone have a clue that I may be missing to install correctly on my Mac with M2?

fedeotaran commented 1 year ago

I was able to install it with this command and using pkg-config! :D

PYTHON_CONFIGURE_OPTS="--with-tcltk-includes='$(pkg-config tk --cflags)' --with-tcltk-libs='$(pkg-config tk --libs)'" asdf install python 3.11.2

python-build 3.11.2 /Users/mitt/.asdf/installs/python/3.11.2
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.11.2.tar.xz...
-> https://www.python.org/ftp/python/3.11.2/Python-3.11.2.tar.xz
Installing Python-3.11.2...
python-build: use tcl-tk from $PYTHON_CONFIGURE_OPTS
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.11.2 to /Users/mitt/.asdf/installs/python/3.11.2
singularitti commented 6 months ago

This works for me! Thanks!

gabrieligbastos commented 3 months ago

Thanks man! :)