cool-easter-32542
04/03/2024, 4:49 PMPyMuPDF python library depends upon a second library, PyMuPDFb (note the trailing b), which contains platform-specific native binaries. When I attempt to run a pants-built application that takes a dependency on PyMuPDF, the app fails to start with the following error:
ImportError: dlopen(/Users/jake/.pex/venvs/b6e643da6d7a238d9690efdaf460876ead6c43f8/779eb2cc0ca9e2fdd204774cbc41848e4e7c5055/lib/python3.12/site-packages/fitz/_extra.cpython-312-darwin.so, 0x0002): Library not loaded: @rpath/libmupdf.dylib
Referenced from: <81DA908A-5E24-3E46-B48D-2001B7D49A66> /Users/jake/.pex/installed_wheels/24c12cd751614658e26581655641e7002ac4c280f91185c4e08d2b1ab0243ce7/PyMuPDF-1.24.0-cp312-none-macosx_11_0_arm64.whl/fitz/_extra.cpython-312-darwin.so
Reason: tried: '/Users/jake/.pex/installed_wheels/24c12cd751614658e26581655641e7002ac4c280f91185c4e08d2b1ab0243ce7/PyMuPDF-1.24.0-cp312-none-macosx_11_0_arm64.whl/fitz/libmupdf.dylib' (no such file), '/Users/jake/.pex/installed_wheels/24c12cd751614658e26581655641e7002ac4c280f91185c4e08d2b1ab0243ce7/PyMuPDF-1.24.0-cp312-none-macosx_11_0_arm64.whl/fitz/libmupdf.dylib' (no such file), '/opt/homebrew/lib/libmupdf.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/lib/libmupdf.dylib' (no such file), '/opt/homebrew/lib/libmupdf.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/lib/libmupdf.dylib' (no such file), '/usr/local/lib/libmupdf.dylib' (no such file), '/usr/lib/libmupdf.dylib' (no such file, not in dyld cache)
(Note: the package name is PyMuPDF, but the module name is fitz.)
The issue appears to be that libmupdf.dylib is not part of the PyMuPDF-1.24.0-cp312-none-macosx_11_0_arm64.whl, but is instead contained within the wheel for its dependency, `PyMuPDFb`. I can't figure out how to get the PyMuPDFb wheel directory into the dynamic linking search path for PyMuPDF.
I've created a minimal reproduction here: https://github.com/jake-normal/fitz-repro/tree/main
Clone that repo and run pants run :dev to recreate the issue.
See also this discussion in Slack: https://pantsbuild.slack.com/archives/C046T6T9U/p1712153616036579
Pants version
2.18.1
OS
MacOS
pantsbuild/pantscool-easter-32542
04/09/2024, 9:31 PM