pyenv install doesn't work with homebrew installed tcl-tk

Created on 18 Jul 2019  Â·  30Comments  Â·  Source: pyenv/pyenv

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:

env CFLAGS="-I/usr/local/opt/tcl-tk/include" CPPFLAGS="-I/usr/local/opt/tcl-tk/include" LDFLAGS="-L/usr/local/opt/tcl-tk/lib"  pyenv install --verbose 3.7.4
env CPPFLAGS="-I/usr/local/opt/tcl-tk/include" LDFLAGS="-L/usr/local/opt/tcl-tk/lib"  PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install --verbose 3.7.4
env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install --verbose 3.7.4

etc.

and then trying to use tkinter from that python:

python -m tkinter -c 'tkinter._test()'                                                                                  
Traceback (most recent call last):
  File "/Users/graham/.pyenv/versions/3.7.4/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/Users/graham/.pyenv/versions/3.7.4/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/graham/.pyenv/versions/3.7.4/lib/python3.7/tkinter/__main__.py", line 7, in <module>
    main()
  File "/Users/graham/.pyenv/versions/3.7.4/lib/python3.7/tkinter/__init__.py", line 3988, in _test
    root = Tk()
  File "/Users/graham/.pyenv/versions/3.7.4/lib/python3.7/tkinter/__init__.py", line 2025, in __init__
    self._loadtk()
  File "/Users/graham/.pyenv/versions/3.7.4/lib/python3.7/tkinter/__init__.py", line 2040, in _loadtk
    % (_tkinter.TK_VERSION, tk_version))
RuntimeError: tk.h version (8.6) doesn't match libtk.a version (8.5)

Looking at the log does it matter that the tcl-tk stuff that is included with macosx is included before the brew ones?

building '_tkinter' extension
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/usr/local/opt/tcl-tk/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/usr/local/opt/tcl-tk/include -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -DWITH_APPINIT=1 -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tcl.framework/Versions/Current/PrivateHeaders -I/System/Library/Frameworks/Tk.framework/Headers -I/System/Library/Frameworks/Tk.framework/Versions/Current/PrivateHeaders -I/usr/X11R6/include -I./Include -I. -I/usr/local/opt/readline/include -I/usr/local/opt/tcl-tk/include -I/usr/local/include -I/private/var/folders/3f/pc11ycws4wsfbw5sk_7s8cfr0000gn/T/python-build.20190718105125.49297/Python-3.7.4/Include -I/private/var/folders/3f/pc11ycws4wsfbw5sk_7s8cfr0000gn/T/python-build.20190718105125.49297/Python-3.7.4 -c /private/var/folders/3f/pc11ycws4wsfbw5sk_7s8cfr0000gn/T/python-build.20190718105125.49297/Python-3.7.4/Modules/_tkinter.c -o build/temp.macosx-10.14-x86_64-3.7/private/var/folders/3f/pc11ycws4wsfbw5sk_7s8cfr0000gn/T/python-build.20190718105125.49297/Python-3.7.4/Modules/_tkinter.o -framework Tk

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

  • [x] Make sure your problem is not listed in the common build problems.
  • [x] Make sure no duplicated issue has already been reported in the pyenv issues. You should look for closed issues, too.
  • [x] Make sure you are not asking us to help solving your specific issue.

    • GitHub issues is opened mainly for development purposes. If you want to ask someone to help solving your problem, go to some community site like Gitter, StackOverflow, etc.

  • [x] Make sure your problem is not derived from packaging (e.g. Homebrew).

    • Please refer to the package documentation for the installation issues, etc.

  • [x] Make sure your problem is not derived from plugins.

    • This repository is maintaining pyenv and the default python-build plugin only. Please refrain from reporting issues of other plugins here.

Description

  • [x] Platform information (e.g. Ubuntu Linux 16.04): mac osx 10.14
  • [x] OS architecture (e.g. amd64):
  • [x] pyenv version: 1.2.13
  • [x] Python version: any
  • [x] C Compiler information (e.g. gcc 7.3):
  • [x] Please attach verbose build log as gist

    • You can turn on verbose debug logging using by setting PYENV_DEBUG=1, e.g. env PYENV_DEBUG=1 pyenv install -v 3.6.4

https://gist.github.com/grahamannett/88a8c06aa864cc38a814046c364537e6

Most helpful comment

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)

  1. install pyenv via homebrew
    $brew install pyenv

  2. install tcl-tk via home brew
    $brew install tcl-tk

  3. 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

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

  1. install Python 3.7.4 in pyenv
    $pyenv install 3.7.4

  2. set the default python version via the global variable and check it
    $pyenv global 3.7.4
    $pyenv version

  3. 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

  4. reset your shell
    $exec "$SHELL"

  5. check your environment
    $which python
    $python -V
    $which pip
    $pip -V

    (check if your pip needs upgrading with $pip install --upgrade pip)

  6. 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:

https://opensource.com/article/19/5/python-3-default-mac

https://github.com/pyenv/pyenv/issues/1125

All 30 comments

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, what brew --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
main()
File "/Users/carroll/.pyenv/versions/3.7.4/lib/python3.7/tkinter/__init__.py", line 3988, in _test
root = Tk()
File "/Users/carroll/.pyenv/versions/3.7.4/lib/python3.7/tkinter/__init__.py", line 2025, in __init__
self._loadtk()
File "/Users/carroll/.pyenv/versions/3.7.4/lib/python3.7/tkinter/__init__.py", line 2040, in _loadtk
% (_tkinter.TK_VERSION, tk_version))
RuntimeError: tk.h version (8.6) doesn't match libtk.a version (8.5)

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)

  1. install pyenv via homebrew
    $brew install pyenv

  2. install tcl-tk via home brew
    $brew install tcl-tk

  3. 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

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

  1. install Python 3.7.4 in pyenv
    $pyenv install 3.7.4

  2. set the default python version via the global variable and check it
    $pyenv global 3.7.4
    $pyenv version

  3. 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

  4. reset your shell
    $exec "$SHELL"

  5. check your environment
    $which python
    $python -V
    $which pip
    $pip -V

    (check if your pip needs upgrading with $pip install --upgrade pip)

  6. 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:

https://opensource.com/article/19/5/python-3-default-mac

https://github.com/pyenv/pyenv/issues/1125

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

Finally succeed with this method!!!

System info

macOS Catalina 10.15.1, tcl-tk 8.6.9, pyenv 1.2.15, and python 3.7.5.

Some Notes for your reference:

  1. 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.

  2. the right path of the python-build should be:
    /usr/local/Cellar/pyenv/1.2.15/plugins/python-build/bin/python-build

  3. 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'

  4. 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

  5. Not necessary to set 'pyenv global 3.7.x', can set pyenv local 3.7.x for target directory

  6. 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.:

  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.1

  1. 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.

I made all the modifications in the last comment, thank you @sri0sharma ! but I'm still getting a version mismatch.. any tips?
python -m tkinter -c 'tkinter._test()' 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:

  1. 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
  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?

see* @ivanoats* comment on this gist at

https://gist.github.com/iexa/2ac761bfd96ab78988b76c030d54a5b8:

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

  1. $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.1

1. 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.:

  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.1

  1. 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.

—
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.

Was this page helpful?
0 / 5 - 0 ratings