I was GOING to ask for help with this annoying problem, but I have solved it and want to document the stupid solution for the next person who searches SO for the string
__cg_jpeg_resync_to_restart and gets (literally) 47 hits.
Here’s the problem: on attempting to use tkinter for the first time with Python3, the following error may occur when you import tkinter:
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/Current/lib/python3.8/lib-dynload/_tkinter.cpython-38-darwin.so, 2): Symbol not found: __cg_jpeg_resync_to_restart Referenced from: /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO Expected in: /usr/local/lib/libJPEG.dylib in /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
Python doc is clear that 3.7+ contain their own copy of tkinter, and in fact the first line above confirms that. So the issue isn’t a wrong version of tkinter or some other tkinter install issue. But tkinter is trying to link to the MacOS copy of ImagIO, and that is trying to dynamically link what should be a perfectly standard thing, libJPEG.dylib. However that lib apparently doesn’t define an entry point
__cg_jpeg_resync_to_restart that ImagIO expects.
This sounds like a version mismatch, ImageIO is getting a JPEG lib of a different version than it expects. But why? I check using homebrew, I have the very latest jpeg (9), it is in
/usr/local/lib/libjpeg.dylib. That's odd, the name is all lowercase? I tell homebrew to uninstall its version of the jpeg cask, and it will not do that because libjpeg is a prereq of ghostscript, imagemagick, and about 6 other things brew has installed.
Most of the SO hits on
__cg_jpeg_resync_to_restart talk about re-aiming DYLD_LIBRARY_PATH various ways and in fact that is the solution. After over 3 hours of futzing around, trying to find other versions of libjpeg, I finally look in the one place that is called out in the message(!),
$ find /System/Library/Frameworks/ImageIO.framework -name '*.dylib' /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libRadiance.dylib /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libJP2.dylib /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libPng.dylib /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libGIF.dylib /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libOpenEXR.dylib /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libJPEG.dylib /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libTIFF.dylib
Bingo. Look, it even uses capital letter JPEG in the name, as in the message! The ImageIO distributed with MacOS has its own private collection of libs, and when I set DYLD_LIBRARY_PATH for Python's use, I confused it. Adding
/System/Library/Frameworks/ImageIO.framework/Versions/A/Resources at the head of DYLD_LIBRARY_PATH before starting Python3 and tkinter imports fine!
It remains to be seen if other modules that expect
libjpeg.dylib version 9 are going to barf now. Or will they ignore libJPEG and go on to /usr/local/libjpeg? I would appreciate comments on that and any issues here.
Answered by user405 on November 14, 2021
2 Asked on July 28, 2020 by vineet-sharma
0 Asked on July 27, 2020 by mia-p
4 Asked on July 26, 2020 by twelsh37
4 Asked on July 25, 2020 by mohsin-ahmed
0 Asked on July 24, 2020 by jack-x
1 Asked on July 24, 2020 by sonu-ishaq
1 Asked on July 24, 2020 by bjorn
3 Asked on July 23, 2020 by themuyu
1 Asked on July 23, 2020 by jacobp
1 Asked on July 22, 2020 by tim496
2 Asked on July 22, 2020 by mmj
4 Asked on July 22, 2020 by doubledouble
Get help from others!