classification
Title: _tkinter built on macOS 10.14 does not link to Tcl and Tk in /Library/Frameworks
Type: Stage:
Components: macOS Versions: Python 3.8, Python 3.7, Python 3.6, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: ned.deily Nosy List: ned.deily, ronaldoussoren, wordtech
Priority: high Keywords:

Created on 2018-10-11 03:29 by wordtech, last changed 2018-10-12 01:57 by wordtech.

Messages (4)
msg327508 - (view) Author: Kevin Walzer (wordtech) * Date: 2018-10-11 03:29
I'm trying to build Python 3.7.0 on macOS 10.14, and Tkinter is not linking to my installation of Tcl/Tk 8.6.8 in /Library/Frameworks. Instead it is linking to the ancient 8.5 Tk installed in /System/Library/Frameworks. My usual way of forcing Python to link to my installation is to edit setup.py and comment out all search directories except /Library/Frameworks, but that seems to be ignored here. My basic invocation is "./configure --enable-framework" which, along with omitting the system libraries from setup.py, has always been sufficient in the past. Please advise.
msg327522 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-10-11 07:44
macOS 10.14 appears to have introduced some subtle differences in the search order for finding header files and/or frameworks and libraries.  I'm not 100% sure I understand completely what has changed but I'm confident that the workaround outlined below should get you going until we have a better solution (but beware of the potential gotcha).

Python has never fully supported building only from an Xcode-only installation, i.e. we have required at a minimum installing system header files into /usr/include et al by using "xcode-select --install".  As of 10.14, xcode-select no longer installs header files in /usr/include.  So that further cripples Python builds in that header files for several third-party libraries shipped with macOS are no longer found, like zlib and sqlite3.  When using an Xcode-only installation (no Command Line Tools) in previous releases of macOS, I believe it was the case that essentially the system root directory ('/') was searched by the compiler tool chain for header files, for libraries, and for frameworks, and for frameworks the long standard fallback framework search path order was honored by default: first search /Library/Frameworks, then /System/Library/Frameworks.  That worked fine if you were installing frameworks like Tcl and TK into /Library/Frameworks and wanting them to override the system ones.  If you did not install the Command Line Tools, then the tool chain used the MacOSX.sdk embedded in Xcode.app as the system root for searching.  By default, that's found in:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk

With an unmodified Xcode install, that directory contains usr and System directories but no Library.  So the contents of /Library were ignored by the tool chain with the net effect that _tkinter builds would also link with the Apple-supplied Tcl and Tk 8.5 in /System/Library/Frameworks.

With 10.14, Xcode-only installs still work the same way but now Command Line Tools seem to effectively use the SDK embedded in /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk as the system root, rather than the system /.  Just like the Xcode copy of the sdk, the CLT copy does not have a Library directory so now the results are the same as Xcode-only builds: _tkinter only links with the /System/Library Tcl and Tk.  From the viewpoint of developers trying to build applications for distribution to others, it makes sense to try to ensure that /Library does not influence the build because /Library is under user control, not the system (Apple).

Until we "recently" started shipping our private version of Tcl and Tk 8.6.x, which we do not install to /Library btw, it made sense to default to linking to /Library and falling back to /System/Library, allowing optional use of a third-party Tcl/Tk (like from ActiveState) and it all sort of worked if you used the tool chain from the CLT.  But with 10.14, that no longer works.  Python's build system complicates this all in large part because the top-level setup.py tries to guess what directories the compiler tool chain are going to search; that was always kind of iffy and now it's much more broken with macOS 10.14.  There are ways to work around most of the issues but we need to have better default behavior.  That's kind of a bigger deal.

For the specific case of building _tkinter to link with Tcl and Tk frameworks in /Library, I think the easiest workaround is to add a Library symlink to the SDK in use, either under /Library/Developer/CommandTools or /Applications/Xcode.app.  "xcode-select --print-path" will show which one is in use, but, alas, not the full path to the SDK.

either:
$ xcode-select --print-path
/Library/Developer/CommandLineTools
$ cd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/

or:
$ xcode-select --print-path
/Applications/Xcode.app/Contents/Developer
$ xcodebuild -version -sdk macosx Path
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
$ cd $(xcodebuild -version -sdk macosx Path)

You can then carefully create a symlink from the SDK to /Library.

$ sudo ln -s /Library .

Now the Python builds should find the Current version of Tcl and Tk frameworks in /Library.

*But* be aware that this might affect other builds if there are other frameworks you have installed in /Library.  So this workaround should be used with caution and you might consider removing the symlink once you are done building Python.

There are other, more complicated workarounds but this seems to me to be the simplest and most foolproof as long as one is aware of the risks and is prepared to potentially recreate the Library symlink after software updates to Xcode or the Command Line Tools.
msg327524 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-10-11 07:51
Correction: in the original second paragraph, the fourth sentence obviously has the case backwards.  It should read:

"When using a *Command Line Tools installation (no Xcode)* in previous releases of macOS, I believe it was the case that essentially the system root directory ('/') was searched by the compiler tool chain for header files, for libraries, and for frameworks, and for frameworks the long standard fallback framework search path order was honored by default: first search /Library/Frameworks, then /System/Library/Frameworks. [...]"
msg327556 - (view) Author: Kevin Walzer (wordtech) * Date: 2018-10-12 01:57
Thank you, this helped.
History
Date User Action Args
2018-10-12 01:57:38wordtechsetmessages: + msg327556
2018-10-11 07:51:45ned.deilysetmessages: + msg327524
2018-10-11 07:44:33ned.deilysetpriority: normal -> high
title: 3.7.0 _tkinter module links against /System/Library/Frameworks -> _tkinter built on macOS 10.14 does not link to Tcl and Tk in /Library/Frameworks
versions: + Python 2.7, Python 3.6, Python 3.8
messages: + msg327522

assignee: ned.deily
2018-10-11 03:29:08wordtechcreate