python build doesn't link with brew tk / tcl #16574

Closed
derekbrokeit opened this Issue Dec 14, 2012 · 10 comments

Projects

None yet

4 participants

@derekbrokeit
Contributor

I built tk with the --enable-threads option to attempt to use a tkinter application that runs in threads. Building tk (with --enable-threads), tcl, and python all work, but the _tkinter.so library does not utilize the homebrew tk library.

$ otool -L Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_tkinter.so
Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_tkinter.so:
        /System/Library/Frameworks/Tcl.framework/Versions/8.5/Tcl (compatibility version 8.5.0, current version 8.5.9)
        /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk (compatibility version 8.5.0, current version 8.5.9)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)

$ otool -L Cellar/python3/3.3.0/Frameworks/Python.framework/Versions/3.3/lib/python3.3/lib-dynload/_tkinter.so
Cellar/python3/3.3.0/Frameworks/Python.framework/Versions/3.3/lib/python3.3/lib-dynload/_tkinter.so:
        /System/Library/Frameworks/Tcl.framework/Versions/8.5/Tcl (compatibility version 8.5.0, current version 8.5.9)
        /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk (compatibility version 8.5.0, current version 8.5.9)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)

I think there should be a way (option?) to install python with the homebrew tk/tcl libraries. Also, if tk and tcl exist, wouldn't it seem reasonable to install with them? Is there something I am missing to easily bypass this and reinstall python linking to the right libraries?

Or, have I made a mistake in some way? Any thoughts, ideas, or help would be appreciated.

@samueljohn
Contributor

True. My Tk is also the system one.
I think we have to (re)work the formula a bit to prefer homebrew's Tk if present.

I can look into this.

@samueljohn
Contributor

Python's configure does not provide an option to specify a certain Tk framework.
I have tried to add depends_on 'tk' if build.include? 'with-brewed-tk but still Python seems to prefer Tk from MacOS X.

@scicalculator let me know if you know a way to persuade python.

@derekbrokeit
Contributor

I looked into it. It seems that the setup.py file in the main directory is called and establishes the libraries. In there are two function (detect_tkinter and detect_tkinter_darwin), which essentially gather information for building the tkinter _tkinter.so library. When it detects OSX, it runs detect_tkinter_darwin, which assumes the location of the Tk framework bundled in OSX. I attempted several ways of getting this library to build differently (they should not be applied at the same time):

  1. https://gist.github.com/4315577
  2. https://gist.github.com/4315577/aff34e8225ac5c42e16bfaadb7c9259e905e27f5

Unfortunately, when I installed python with either of these patches, it resulted in no tkinter library bundled with python. That means import Tkinter throws an exception ImportError: no _tkinter.so (something like that). I did not see when any error message occured. However, there is indeed a _tkiner.so file in the build directory (the file exists), but for some reason, it is not in the final Cellar.

I don't have time to go any further into it right now, but at least it's a start. Hope that can get us on the right path.

@samueljohn
Contributor

Nice investigative work!
Does the _tkinter.so in the build dir link to Tk?

To me this looks as if python on OS X only wants the Tk.framework. In
any way we would need to hack this.
Is it worth it? You are more familiar with Tk. 10.8.2 has got Tk 8.5.
What features do you need?

@derekbrokeit
Contributor

I don't know what I am doing wrong, but I found that macports uses a very similar method to 2 above, which I think is the best way (https://gist.github.com/4315577/aff34e8225ac5c42e16bfaadb7c9259e905e27f5).

$ otool -L build/lib.macosx-10.8-x86_64-2.7/_tkinter.so
build/lib.macosx-10.8-x86_64-2.7/_tkinter.so:
        /usr/local/lib/libtk8.5.dylib (compatibility version 8.5.0, current version 8.5.9)
        /usr/local/lib/libtcl8.5.dylib (compatibility version 8.5.0, current version 8.5.9)
        /opt/X11/lib/libX11.6.dylib (compatibility version 10.0.0, current version 10.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)

You can see that the library is properly linked as far as I can tell. The problem is, it doesn't come over from the build directory into the compiled framework.

@derekbrokeit
Contributor

Interesting, I just did 2 tests. I halted the brew installation after configure. Then I entered the shell (brew install --debug python). If I then use make it creates _tkinter.so. However, if I halt the brew installation after it uses system 'make' I find no _tkinter.so. What is different between brew using make and my shell using make that there is this difference? That is what is important here. I'll report when I figure it out.

@samueljohn
Contributor

A while back I had to add the header directory explicitly for the Tk shipped with OS X. Now, I have to disable that for --with-brewed-tk. Check out my pull request and tell me if it builds for you. Thanks for the patch, I pasted that one into the formula.

@samueljohn
Contributor

#16626 is on hold currently (temporarily closed), because we wait for Homebrew/homebrew-dupes#132 first.

@samueljohn samueljohn added a commit to samueljohn/homebrew that referenced this issue Jan 11, 2013
@samueljohn samueljohn python: Allow --with-brewed-tk.
- Fixes #16574.
- Improve Tkinter test by actually calling Tk()
- Check for /Library/Frameworks/Tk.framework no longer needed.
- Fix PYTHONFRAMEWORKDIR so that `python-config --ldflags` is useful.
7941a97
@MikeMcQuaid MikeMcQuaid added a commit that closed this issue Jan 11, 2013
@samueljohn @MikeMcQuaid samueljohn + MikeMcQuaid python: Allow --with-brewed-tk.
- Fixes #16574.
- Improve Tkinter test by actually calling Tk()
- Check for /Library/Frameworks/Tk.framework no longer needed.
- Fix PYTHONFRAMEWORKDIR so that `python-config --ldflags` is useful.

Closes #16626.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
1d8f01d
@samueljohn
Contributor

@scicalculator please let me know if it works now for you

@MikeMcQuaid MikeMcQuaid added a commit that referenced this issue Jan 11, 2013
@MikeMcQuaid MikeMcQuaid Revert "python: Allow --with-brewed-tk."
This reverts commit 1d8f01d.

Reopens #16626, reopens #16574.
cc2b8b3
@MikeMcQuaid MikeMcQuaid reopened this Jan 11, 2013
@MikeMcQuaid
Member

Reverted that commit, sorry.

@samueljohn samueljohn added a commit to samueljohn/homebrew that referenced this issue Jan 11, 2013
@samueljohn samueljohn python: Allow --with-brewed-tk.
- Fixes #16574.
- Improve Tkinter test by actually calling Tk()
- Check for /Library/Frameworks/Tk.framework no longer needed.
- Also remove Tk.framework check from python3.rb
- Fix PYTHONFRAMEWORKDIR so that `python-config --ldflags` is useful.
90f5168
@dholm dholm added a commit to dholm/homebrew that referenced this issue Jan 14, 2013
@samueljohn @dholm samueljohn + dholm python: Allow --with-brewed-tk.
- Fixes #16574.
- Improve Tkinter test by actually calling Tk()
- Check for /Library/Frameworks/Tk.framework no longer needed.
- Fix PYTHONFRAMEWORKDIR so that `python-config --ldflags` is useful.

Closes #16626.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
3fc5b59
@dholm dholm added a commit to dholm/homebrew that referenced this issue Jan 14, 2013
@MikeMcQuaid @dholm MikeMcQuaid + dholm Revert "python: Allow --with-brewed-tk."
This reverts commit 1d8f01d.

Reopens #16626, reopens #16574.
288689a
@adamv adamv added a commit that closed this issue Jan 15, 2013
@samueljohn @adamv samueljohn + adamv python: Allow --with-brewed-tk.
- Fixes #16574.
- Improve Tkinter test by actually calling Tk()
- Check for /Library/Frameworks/Tk.framework no longer needed.
- Also remove Tk.framework check from python3.rb
- Fix PYTHONFRAMEWORKDIR so that `python-config --ldflags` is useful.

Closes #17008.

Signed-off-by: Adam Vandenberg <flangy@gmail.com>
3defd78
@adamv adamv closed this in 3defd78 Jan 15, 2013
@norioxkimura norioxkimura added a commit to norioxkimura/homebrew that referenced this issue Jan 16, 2013
@samueljohn @norioxkimura samueljohn + norioxkimura python: Allow --with-brewed-tk.
- Fixes #16574.
- Improve Tkinter test by actually calling Tk()
- Check for /Library/Frameworks/Tk.framework no longer needed.
- Fix PYTHONFRAMEWORKDIR so that `python-config --ldflags` is useful.

Closes #16626.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
f2c4d04
@norioxkimura norioxkimura added a commit to norioxkimura/homebrew that referenced this issue Jan 16, 2013
@MikeMcQuaid @norioxkimura MikeMcQuaid + norioxkimura Revert "python: Allow --with-brewed-tk."
This reverts commit 1d8f01d.

Reopens #16626, reopens #16574.
6947e80
@norioxkimura norioxkimura added a commit to norioxkimura/homebrew that referenced this issue Jan 16, 2013
@samueljohn @norioxkimura samueljohn + norioxkimura python: Allow --with-brewed-tk.
- Fixes #16574.
- Improve Tkinter test by actually calling Tk()
- Check for /Library/Frameworks/Tk.framework no longer needed.
- Also remove Tk.framework check from python3.rb
- Fix PYTHONFRAMEWORKDIR so that `python-config --ldflags` is useful.

Closes #17008.

Signed-off-by: Adam Vandenberg <flangy@gmail.com>
6137dcd
@xu-cheng xu-cheng locked and limited conversation to collaborators Feb 16, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.