Closed grahamannett closed 4 years ago
For reference these people seem to have this issue as well: https://github.com/jiansoung/issues-list/issues/15
This seems like its the same issue as: https://github.com/pyenv/pyenv/issues/1125
In my case, in the verbose log of pyenv I get the following error when trying to build tkinter.
clang: warning: -framework Tk: 'linker' input unused [-Wunused-command-line-argument]
In file included from /private/var/folders/0f/0723vl7935166wxgzrtcm3vw0000gn/T/python-build.20190719020206.17065/Python-2.7.16/Modules/_tkinter.c:71:
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/tk.h:78:11: fatal error: 'X11/Xlib.h' file not found
# include <X11/Xlib.h>
^~~~~~~~~~~~
1 error generated.
Interesting thing is: it works without problem with python 3.5.7, but not with 2.7.16. In fact, in both cases I uninstalled the corresponding python and reinstalled it after brew install tcl-tk
. With python3 it worked, but not with python2.7.16.
Ok, a comment on my previous comment. I tried to pyenv install 3.7.4
out of curiosity, and it still fails, generating the same error. So, I am not sure what happened in the mean time and why it worked on my 3.5.7 installation. It was a couple of months ago when I did it for the 3.5.7 with success.
Ok, the problem was actually quite clear from my error log. pyenv looks for tk inside the macos sdk, while it should look into the brew installation, if existent, pretty much like it works with zlib.
I believe this should be fixed in pyenv.
A temporary fix is to run:
CFLAGS="-I$(brew --prefix tcl-tk)/include" pyenv install 2.7.16
@sartorg I think I had tried that and it didn't work for me. I dont really want to try it again since I ended up editing my python-build file to just have the tcl-tk stuff hard coded.
@grahamannett Well, if it is just out of curiosity, you can pyenv install
another random python version (like 3.7.3) and delete if afterwards.
If you are willing to do that, could you post the verbose log of the lines when it tries to compile Tk?
Also, what brew --prefix tcl-tk
returns for you?
In any case, I am happy you solved it!
I am also seeing this.
When installing python 3.7.4 using pyenv, why doesn't pyenv use tcl-tk from homebrew like it does for openssl and readline? There should be a way to force pyenv to check for a brew installation of tcl-tk and if it exists then use it.
@grahamannett Well, if it is just out of curiosity, you can
pyenv install
another random python version (like 3.7.3) and delete if afterwards. If you are willing to do that, could you post the verbose log of the lines when it tries to compile Tk? Also, whatbrew --prefix tcl-tk
returns for you? In any case, I am happy you solved it!
I just ran this and I get /usr/local/opt/tcl-tk
I'm going to try your suggested CFLAGS and see if that works on my 10.14.6 system.
Ok, the problem was actually quite clear from my error log. pyenv looks for tk inside the macos sdk, while it should look into the brew installation, if existent, pretty much like it works with zlib. I believe this should be fixed in pyenv. A temporary fix is to run:
CFLAGS="-I$(brew --prefix tcl-tk)/include" pyenv install 2.7.16
@sartorg I tried installing like this (using install 3.7.4) and I still get
iMac:~ carroll$ python -m tkinter -c 'tkinter._test()
Traceback (most recent call last):
File "/Users/carroll/.pyenv/versions/3.7.4/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/Users/carroll/.pyenv/versions/3.7.4/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/carroll/.pyenv/versions/3.7.4/lib/python3.7/tkinter/main.py", line 7, in
My log file of the install of 3.7.4 shows the brew installation of tcl-tk is being pulled in. pyenv.log
This is becoming maddening!
Finally! After all of this, I got it to install! Whew! Here's what I did so it may help others:
PyEnv Python installation steps to get the latest tcl/tk version on Mac OS 10.14.6 (Mojave)
$brew install pyenv
NOTE: As of this update Homebrew will install the Arm version of pyenv in /opt/homebrew/pyenv.
$brew install tcl-tk
NOTE: As of this update Homebrew will installs the Arm version of tcl-tk in /opt/homebrew/tcl-tk.
to get tcl-tk 8.6 to work with the pyenv install of python, you must edit the python-build script file. It may be located in one these two locations:
~/.pyenv/plugins/python-build/bin/python-build
or:
/usr/local/Cellar/pyenv/1.2.13/plugins/python-build/bin/python-build
NOTE: For the Arm version you will need to edit /opt/homebrew/Cellar/pyenv/1.2.22/plugins/python-build/bin/python-build
Once you have the script file open, search for:
$CONFIGURE_OPTS ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1
and replace with:
$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' ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1
NOTE: For the Arm build it will have to read $CONFIGURE_OPTS --with-tcltk-includes='-I/opt/homebrew/Cellar/tcl-tk/8.6.11/include' --with-tcltk-libs='-L/opt/homebrew/Cellar/tcl-tk/8.6.11/lib -ltcl8.6 -ltk8.6' ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1
$pyenv install 3.7.4
NOTE: For Arm version $pyenv install 3.9.1
set the default python version via the global variable and check it
$pyenv global 3.7.4
or $pyenv global 3.9.1
$pyenv version
Add to your .bash_profile to set the pyenv every time you load your shell $echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
reset your shell
$exec "$SHELL"
check your environment
$which python
$python -V
$which pip
$pip -V
(check if your pip needs upgrading with $pip install --upgrade pip
)
Test your tcl-tk installation with $python -m tkinter -c 'tkinter._test()'
If you don't get any errors when running the above test, your installation should work
Credits:
this should be fixed with #1397. when installing I was using/testing with
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'" pyenv install 3.7.4
macOS Catalina 10.15.1, tcl-tk 8.6.9, pyenv 1.2.15, and python 3.7.5.
DO NOT brew install python
before Step 4 install python in pyenv
, as this MacOS homebrew python 3.7.x with tcl-tk did. If installed, uninstall it.
the right path of the python-build
should be:
/usr/local/Cellar/pyenv/1.2.15/plugins/python-build/bin/python-build
Better insert
the additional arguments to the original python-build
to keep in one line when editing with vim/vi...
--with-tcltk-includes='-I/usr/local/opt/tcl-tk/include' --with-tcltk-libs='-L/usr/local/opt/tcl-tk/lib -ltcl8.6 -ltk8.6'
if you need to use PyInstaller
, which require CPython installation built, the step 4 should be
$ env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.7.x
Not necessary to set 'pyenv global 3.7.x', can set pyenv local 3.7.x
for target directory
in this target directory further use pipenv install
to get a virtual env with python 3.7.x
, which is OK for tkinter
If people are still seeing this and having issues, theres a better PR made that will automatically check for tcl-tk homebrew installed https://github.com/pyenv/pyenv/pull/1409
I don't know what the similar way to do this for linux related installs would be but hopefully it's merged at some point? If someone can explain how to create and test this issue in a linux distro, I would be happy to look into.
Also if someone has an idea for how to test this (as the only way I have been able to reliably tell is something along the lines of python -m tkinter -c 'tkinter._test()'
and verifying the popup box), please let me know!
@grahamannett works for me, thx!
@grahamannett, thanks much for your post. I spent quite a bit of time, failing and failing again, and then I finally succeeded. For others who are novice like me, I am listing the steps I took to successfully install tcl-tk and IDLE to work in MacOS Catalina (10.15.3). It's mostly yours, with a few additional in between.:
ran $brew install pyenv
Output: Warning: pyenv 1.2.16 is already installed and up-to-date
To reinstall 1.2.16, ran brew reinstall pyenv
/usr/local/Cellar/pyenv/1.2.16: 671 files, 2.5MB
ran $brew install tcl-tk
Output: tcl-tk 8.6.10 is already installed and up-to-date
To reinstall 8.6.10, run brew reinstall tcl-tk
Output after brew reinstall tcl-tk
:
tcl-tk is keg-only, which means it was not symlinked into /usr/local,
because tk installs some X11 headers and macOS provides an (older) Tcl/Tk.
If you need to have tcl-tk first in your PATH run: echo 'export PATH="/usr/local/opt/tcl-tk/bin:$PATH"' >> ~/.zshrc (I added it to ~/.zshrc as the first line)
For compilers to find tcl-tk you may need to set:
export LDFLAGS="-L/usr/local/opt/tcl-tk/lib"
export CPPFLAGS="-I/usr/local/opt/tcl-tk/include"
(I added these two to ~/.zshrc, too, after adding the above)
For pkg-config to find tcl-tk you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/tcl-tk/lib/pkgconfig"
(I added this to ~/.zshrc, too, after adding the above)
To get tcl-tk 8.6 to work with the pyenv install of python, I found: /usr/local/Cellar/pyenv/1.2.13/plugins/python-build/bin/python-build and replaced the following: $CONFIGURE_OPTS ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1 with: $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' ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1
ran $pyenv install 3.8.1
Installed Python-3.8.1 to /Users/ryan/.pyenv/versions/3.8.1
ran $pyenv global 3.8.1
Refreshed the current terminal and checked by running
$pyenv version
output: 3.8.1 (set by /Users/ryan/.pyenv/version)
Ran $python -V
output: Python 3.8.1
ran $pip install --upgrade
pip (since I had previously already installed pip using $pip install
)
output: Successfully installed pip-20.0.2
Tested my tcl-tk installation with $python -m tkinter -c 'tkinter._test()'
Output: Tk window popped up. Hit ‘Quit’ to back to Terminal.
Ran $ idle
Output: Python 3.8.1 Shell window popped up.
I made all the modifications in the last comment, thank you @sri0sharma ! but I'm still getting a version mismatch.. any tips?
DEPRECATION WARNING: The system version of Tk is deprecated and may be removed in a future release. Please don't rely on it. Set TK_SILENCE_DEPRECATION=1 to suppress this warning.
Traceback (most recent call last):
File "/Users/ivan/.pyenv/versions/3.8.1/lib/python3.8/runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/Users/ivan/.pyenv/versions/3.8.1/lib/python3.8/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/Users/ivan/.pyenv/versions/3.8.1/lib/python3.8/tkinter/__main__.py", line 7, in <module>
main()
File "/Users/ivan/.pyenv/versions/3.8.1/lib/python3.8/tkinter/__init__.py", line 4552, in _test
root = Tk()
File "/Users/ivan/.pyenv/versions/3.8.1/lib/python3.8/tkinter/__init__.py", line 2263, in __init__
self._loadtk()
File "/Users/ivan/.pyenv/versions/3.8.1/lib/python3.8/tkinter/__init__.py", line 2279, in _loadtk
raise RuntimeError("tk.h version (%s) doesn't match libtk.a version (%s)"
RuntimeError: tk.h version (8.6) doesn't match libtk.a version (8.5)
Hi @ivanoats, I am not an expert. I got my python and tck running by trial and error. I campared your files "/Users/ivan/.pyenv/versions/3.8.1/lib/python3.8/runpy.py", "/Users/ivan/.pyenv/versions/3.8.1/lib/python3.8/tkinter/main.py", and "/Users/ivan/.pyenv/versions/3.8.1/lib/python3.8/tkinter/init.py" with mine, and they are exactly the same on the respective lines. The only thing which comes to my mind is the following:
if the step 3 was properly executed: To get tcl-tk 8.6 to work with the pyenv install of python, you must edit the python-build script file. It may be located in one these two locations (I may have gotten this from https://stackoverflow.com/questions/28921333/installed-python-3-on-mac-os-x-but-its-still-python-2-7): ~/.pyenv/plugins/python-build/bin/python-build or: /usr/local/Cellar/pyenv/1.2.13/plugins/python-build/bin/python-build Once you have the script file open, search for: $CONFIGURE_OPTS ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1 and replace with: $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' ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1
if your ~/.zshrc file is OK? By the way, did you add the following to your ~/.zshrc for python version to work ok: if command -v pyenv 1>/dev/null 2>&1; then eval "$(pyenv init -)" fi These three are the last three lines in my ~/.zshrc for python version to come out correctly. I do not know if it will resolve your tk.h version problem.
I don't exactly recall, but I had to try a few times, before my steps worked. In fact, I did uninstall my brew and pyenv and did clean install again for these steps to work. Good luck!
This issue was closed, but how was it resolved? I see lots of disparate things that people have done - but which one works?
"FWIW, I tried both the pyenv and the homebrew replacement and only the homebrew replacement really worked. Thank you !"
Basically, you need to do a clean pyenv and homebrew install in the order listed under @sri0sharma at https://github.com/pyenv/pyenv/issues/1375.
Good luck!
On Fri, Apr 24, 2020 at 5:36 AM Nat Ersoz notifications@github.com wrote:
This issue was closed, but how was it resolved? I see lots of disparate things that people have done - but which one works?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pyenv/pyenv/issues/1375#issuecomment-618731860, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHQZTXTCQKU7UW44WYRKXLLRODJWRANCNFSM4IE6L7XA .
Similar to others, this link (https://stackoverflow.com/questions/60469202/unable-to-install-tkinter-with-pyenv-pythons-on-macos/60469203#60469203) fixed everything, and I did not have to manually deal with the build files etc. It even has a comment about the error that gets thrown for 8.5 versus 8.6. Worked perfectly for me, hope it helps you out too.
Thanks much, Jenna.
In fact, I figured it out a few months ago (sometime in Feb), and posted my detailed solutions at two places on github (see: https://github.com/pyenv/pyenv/issues/1375#issuecomment-589964703). Many people have already used them as I keep getting their emails in acknowledgement. Somehow I forgot that I had posted my questions first at stackflow.com, as I wanted to post my solution there, too, but could not remember at that time.
Sri
On Thu, Jun 4, 2020 at 10:22 PM Jenna Pearson notifications@github.com wrote:
Similar to others, this link ( https://stackoverflow.com/questions/60469202/unable-to-install-tkinter-with-pyenv-pythons-on-macos/60469203#60469203) fixed everything, and I did not have to manually deal with the build files etc. It even has a comment about the error that gets thrown for 8.5 versus 8.6. Worked perfectly for me, hope it helps you out too.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pyenv/pyenv/issues/1375#issuecomment-638978320, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHQZTXWS7MUNXSAE5Y5M5SLRU7GOFANCNFSM4IE6L7XA .
No problem :) I was thankful for your thread!
Best,
Jenna Lynn Pearson Ph.D. Candidate Department of Earth, Environmental, and Planetary Sciences Brown University, Providence, RI 02912 USA https://jlpearso.github.io/
On Thu, 4 Jun 2020 at 12:35, Ryan notifications@github.com wrote:
Thanks much, Jenna.
In fact, I figured it out a few months ago (sometime in Feb), and posted my detailed solutions at two places on github (see: https://github.com/pyenv/pyenv/issues/1375#issuecomment-589964703). Many people have already used them as I keep getting their emails in acknowledgement. Somehow I forgot that I had posted my questions first at stackflow.com, as I wanted to post my solution there, too, but could not remember at that time.
Sri
On Thu, Jun 4, 2020 at 10:22 PM Jenna Pearson notifications@github.com wrote:
Similar to others, this link (
https://stackoverflow.com/questions/60469202/unable-to-install-tkinter-with-pyenv-pythons-on-macos/60469203#60469203 ) fixed everything, and I did not have to manually deal with the build files etc. It even has a comment about the error that gets thrown for 8.5 versus 8.6. Worked perfectly for me, hope it helps you out too.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pyenv/pyenv/issues/1375#issuecomment-638978320, or unsubscribe < https://github.com/notifications/unsubscribe-auth/AHQZTXWS7MUNXSAE5Y5M5SLRU7GOFANCNFSM4IE6L7XA
.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/pyenv/pyenv/issues/1375#issuecomment-639072409, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHW6P3DNEVJHLQO4JCKSFIDRU7ZRTANCNFSM4IE6L7XA .
- $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' ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1
This method worked for me.
@grahamannett, thanks much for your post. I spent quite a bit of time, failing and failing again, and then I finally succeeded. For others who are novice like me, I am listing the steps I took to successfully install tcl-tk and IDLE to work in MacOS Catalina (10.15.3). It's mostly yours, with a few additional in between.:
1. ran $`brew install pyenv` Output: Warning: pyenv 1.2.16 is already installed and up-to-date To reinstall 1.2.16, ran `brew reinstall pyenv` /usr/local/Cellar/pyenv/1.2.16: 671 files, 2.5MB 2. ran $`brew install tcl-tk`
Output: tcl-tk 8.6.10 is already installed and up-to-date To reinstall 8.6.10, run
brew reinstall tcl-tk
Output after
brew reinstall tcl-tk
: tcl-tk is keg-only, which means it was not symlinked into /usr/local, because tk installs some X11 headers and macOS provides an (older) Tcl/Tk.If you need to have tcl-tk first in your PATH run: echo 'export PATH="/usr/local/opt/tcl-tk/bin:$PATH"' >> ~/.zshrc (I added it to ~/.zshrc as the first line)
For compilers to find tcl-tk you may need to set:
export LDFLAGS="-L/usr/local/opt/tcl-tk/lib"
export CPPFLAGS="-I/usr/local/opt/tcl-tk/include"
(I added these two to ~/.zshrc, too, after adding the above)For pkg-config to find tcl-tk you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/tcl-tk/lib/pkgconfig"
(I added this to ~/.zshrc, too, after adding the above)1. To get tcl-tk 8.6 to work with the pyenv install of python, I found: /usr/local/Cellar/pyenv/1.2.13/plugins/python-build/bin/python-build and replaced the following: $CONFIGURE_OPTS ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1 with: $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' ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1 2. ran $`pyenv install 3.8.1` Installed Python-3.8.1 to /Users/ryan/.pyenv/versions/3.8.1 3. ran $`pyenv global 3.8.1` Refreshed the current terminal and checked by running 4. $`pyenv version` output: 3.8.1 (set by /Users/ryan/.pyenv/version)
Ran $
python -V
output: Python 3.8.11. ran $`pip install --upgrade` pip (since I had previously already installed pip using $`pip install`) output: Successfully installed pip-20.0.2 2. Tested my tcl-tk installation with $`python -m tkinter -c 'tkinter._test()'` Output: Tk window popped up. Hit ‘Quit’ to back to Terminal. 3. Ran $ `idle` Output: Python 3.8.1 Shell window popped up.
This worked for me with a few small adjustments.
Instead of ~/.zshrc I had to put the export statements into ~/.profile because I'm using bash. The version of pyenv has changed so the path to the pyenv python-build file changed and 1.2.13 needed to be replaced with my version. Lastly I uninstalled the previous version I had installed withpyenv uninstall 3.5.8
and then re-installed.
This solution also works with pipenv which uses pyenv to install python.
Thanks, Ralph. Good to know it worked for you. Thank you for updating it.
On Thu, Jul 2, 2020 at 10:21 PM Ralph Ritoch notifications@github.com wrote:
@grahamannett https://github.com/grahamannett, thanks much for your post. I spent quite a bit of time, failing and failing again, and then I finally succeeded. For others who are novice like me, I am listing the steps I took to successfully install tcl-tk and IDLE to work in MacOS Catalina (10.15.3). It's mostly yours, with a few additional in between.:
ran $
brew install pyenv
Output: Warning: pyenv 1.2.16 is already installed and up-to-date
To reinstall 1.2.16, ran
brew reinstall pyenv
/usr/local/Cellar/pyenv/1.2.16: 671 files, 2.5MB
ran $
brew install tcl-tk
Output: tcl-tk 8.6.10 is already installed and up-to-date To reinstall 8.6.10, run brew reinstall tcl-tk
Output after brew reinstall tcl-tk: tcl-tk is keg-only, which means it was not symlinked into /usr/local, because tk installs some X11 headers and macOS provides an (older) Tcl/Tk.
If you need to have tcl-tk first in your PATH run: echo 'export PATH="/usr/local/opt/tcl-tk/bin:$PATH"' >> ~/.zshrc (I added it to ~/.zshrc as the first line)
For compilers to find tcl-tk you may need to set: export LDFLAGS="-L/usr/local/opt/tcl-tk/lib" export CPPFLAGS="-I/usr/local/opt/tcl-tk/include" (I added these two to ~/.zshrc, too, after adding the above)
For pkg-config to find tcl-tk you may need to set: export PKG_CONFIG_PATH="/usr/local/opt/tcl-tk/lib/pkgconfig" (I added this to ~/.zshrc, too, after adding the above)
To get tcl-tk 8.6 to work with the pyenv install of python, I found:
/usr/local/Cellar/pyenv/1.2.13/plugins/python-build/bin/python-build
and replaced the following:
$CONFIGURE_OPTS ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1
with:
$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' ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1
ran $
pyenv install 3.8.1
Installed Python-3.8.1 to /Users/ryan/.pyenv/versions/3.8.1
ran $
pyenv global 3.8.1
Refreshed the current terminal and checked by running
$
pyenv version
output: 3.8.1 (set by /Users/ryan/.pyenv/version)
Ran $python -V output: Python 3.8.1
ran $
pip install --upgrade
pip (since I had previously already installed pip using $pip install
)output: Successfully installed pip-20.0.2
Tested my tcl-tk installation with $
python -m tkinter -c 'tkinter._test()'
Output: Tk window popped up. Hit ‘Quit’ to back to Terminal.
Ran $
idle
Output: Python 3.8.1 Shell window popped up.
This worked for me with a few small adjustments.
Instead of ~/.zshrc I had to put the export statements into ~/.profile because I'm using bash. The version of pyenv has changed so the path to the pyenv python-build file changed and 1.2.13 needed to be replaced with my version. Lastly I uninstalled the previous version I had installed withpyenv uninstall 3.5.8 and then re-installed.
This solution also works with pipenv which uses pyenv to install python.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pyenv/pyenv/issues/1375#issuecomment-653116972, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHQZTXVZEP7RAPLC4TOGD23RZS3JLANCNFSM4IE6L7XA .
The easier way to do this w/o editing homebrew files is provided by the PR described here and the command line to do it is e.g.
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'" pyenv install 3.8.3
Building on @elgow's comment, this also worked for me with no editing of pyenv or .zshrc (including --enable-shared or --enable-framework), albeit with a slight adjustment (mainly adding env
to the front of the line):
env 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' --enable-shared" pyenv install 3.8.5
I ran into the same problem and I tried everything I can, but it still can't find where the _tkinter module is
Finially, this works:
brew uninstall pyenv
brew install python3
Then, tkinter is perfect to use. Goodbye pyenv.
My nickel into the tkinter on OS X community stash: As you value your life or your reason, keep away from the pyenv. Go conda.
I have the same issue on arch: why isn't tkinter compiled with python?
Thanks a lot for the solution! For people who are following this tutorial, be sure to change to your current pyenv version in the line
/usr/local/Cellar/pyenv/1.2.13/plugins/python-build/bin/python-build
if it is your path for the python-build script.
Hello,
My name is Aarushi Sharma. You may have been trying to contact my father, Srinarayan Sharma. Sadly, he died of COVID-19 pneumonia on April 24th, 2021 and will no longer be able to respond to any emails or complete any requests.
I hope this email hasn’t inconvenienced you too much. I’m really sorry for any complications this may have caused.
Yours, Aarushi Sharma
On Thursday, May 20, 2021, Clément Verrier @.***> wrote:
Thanks a lot for the solution! For people who are following this tutorial, be sure to change the line
/usr/local/Cellar/pyenv/1.2.13/plugins/python-build/bin/python-build
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pyenv/pyenv/issues/1375#issuecomment-844853061, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHQZTXSCG3CHFT2E7YSRFEDTOTBD3ANCNFSM4IE6L7XA .
I made all the modifications in the last comment, thank you @sri0sharma ! but I'm still getting a version mismatch.. any tips?
DEPRECATION WARNING: The system version of Tk is deprecated and may be removed in a future release. Please don't rely on it. Set TK_SILENCE_DEPRECATION=1 to suppress this warning. Traceback (most recent call last): File "/Users/ivan/.pyenv/versions/3.8.1/lib/python3.8/runpy.py", line 193, in _run_module_as_main return _run_code(code, main_globals, None, File "/Users/ivan/.pyenv/versions/3.8.1/lib/python3.8/runpy.py", line 86, in _run_code exec(code, run_globals) File "/Users/ivan/.pyenv/versions/3.8.1/lib/python3.8/tkinter/__main__.py", line 7, in <module> main() File "/Users/ivan/.pyenv/versions/3.8.1/lib/python3.8/tkinter/__init__.py", line 4552, in _test root = Tk() File "/Users/ivan/.pyenv/versions/3.8.1/lib/python3.8/tkinter/__init__.py", line 2263, in __init__ self._loadtk() File "/Users/ivan/.pyenv/versions/3.8.1/lib/python3.8/tkinter/__init__.py", line 2279, in _loadtk raise RuntimeError("tk.h version (%s) doesn't match libtk.a version (%s)" RuntimeError: tk.h version (8.6) doesn't match libtk.a version (8.5)
I've faced the same situation and I finally figured out that I didn't install virtualenv
.
After I installed the plugin virtualenv
and reinstall the python via pyenv install 3.x.x, everything works as expected.
I was able to fix it by following these two steps.
Using tkinter
with pyenv
can be tricky due to missing dependencies.
First, let's make sure we have installed the necessary system packages for tkinter
.
In most Linux systems, you can install them with the following commands:
sudo apt-get update
sudo apt-get install tk-dev
On macOS, you can use Homebrew to achieve the same:
brew install tcl-tk
Next, make sure you link the correct versions of Tcl/Tk when installing Python. pyenv
builds Python in your environment, but if you don't have the required dependencies, like the Tk/Tcl libraries, it'll build Python without them.
If the Python version you want to use is already installed on your system, you'll need to uninstall it before proceeding. For example:
pyenv uninstall 3.11.3
When installing a new Python version with pyenv
, use the following commands:
For Linux:
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev python-openssl git
env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install <version>
For macOS, after installing tcl-tk with brew:
brew install openssl readline sqlite3 xz zlib
env LDFLAGS="-L$(brew --prefix openssl@1.1)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix sqlite3)/lib -L$(brew --prefix xz)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix tcl-tk)/lib" \
CPPFLAGS="-I$(brew --prefix openssl@1.1)/include -I$(brew --prefix readline)/include -I$(brew --prefix sqlite3)/include -I$(brew --prefix xz)/include -I$(brew --prefix zlib)/include -I$(brew --prefix tcl-tk)/include" \
PKG_CONFIG_PATH="$(brew --prefix openssl@1.1)/lib/pkgconfig:$(brew --prefix readline)/lib/pkgconfig:$(brew --prefix sqlite3)/lib/pkgconfig:$(brew --prefix xz)/lib/pkgconfig:$(brew --prefix zlib)/lib/pkgconfig:$(brew --prefix tcl-tk)/lib/pkgconfig" \
pyenv install <version>
Replace <version>
with the version of Python you want to install. After that, you should be able to import tkinter
in your pyenv
Python environment.
Note that I couldn't get tkinter
to work with pyenv
on Python 3.11.0
, but it worked perfectly on 3.11.2
.
Installing tcl-tk and python
/ following tkdocs works:
PYTHON_CONFIGURE_OPTS="--with-tcltk-includes='-I/Library/Frameworks/Tcl.framework/Headers|-I/Library/Frameworks/Tk.framework/Headers' --with-tcltk-libs='/Library/Frameworks/Tcl.framework/Tcl|/Library/Frameworks/Tk.framework/Tk'" pyenv install 3.11
When installing any version of python with pyenv, I can't get tkinter to work. Python install fine but I believe that the files related to tcl-tk are causing issues and python-build either needs to skip the files related in
For instance with python installed from pyenv in any manner of way:
etc.
and then trying to use tkinter from that python:
Looking at the log does it matter that the tcl-tk stuff that is included with macosx is included before the brew ones?
For why I think it has to do with pyenv/python-build, the brew installed python 3 works with tkinter
/usr/local/bin/python3 -c 'import tkinter; tkinter._test()'
Too many issues will kill our team's development velocity, drastically. Make sure you have checked all steps below.
Prerequisite
pyenv
and the defaultpython-build
plugin only. Please refrain from reporting issues of other plugins here.Description
PYENV_DEBUG=1
, e.g.env PYENV_DEBUG=1 pyenv install -v 3.6.4
https://gist.github.com/grahamannett/88a8c06aa864cc38a814046c364537e6