Howdy :wave: . Looking for quick eyes on something...
# general
p
Howdy 👋 . Looking for quick eyes on something. I've been running into a strange issue somewhere at the intersection of pants, pex, and wheels. When I take a dependency on the
PyMuPDF
python package, my app fails to start with a dynamic linking issue:
Copy code
ImportError: dlopen(/Users/jake/.pex/venvs/721947db45864b75a0373c21d4d1aabf0829cb39/779eb2cc0ca9e2fdd204774cbc41848e4e7c5055/lib/python3.11/site-packages/fitz/_extra.cpython-311-darwin.so, 0x0002): Library not loaded: @rpath/libmupdf.dylib
I've created a minimal reproduction of the issue here: https://github.com/jake-normal/fitz-repro/tree/main
you will run into the problem if you run
pants run :dev
b
I’ve run into this recently as well on our work repo, and from what I can tell it breaks for specific versions of
PyMuPDF
. We upgraded from version
1.24.0
to version
1.24.1
and we got a pretty similar error.
p
ah, interesting
yeah I suspected it had something to do with `PyMuPDF`'s wheel packaging
you've had success with 1.24.0 though?
b
I’m trying to see if that will work with your example repo. 1.24.0 has worked well for us at work though
p
I just tried
1.24.0
in my repro repo and it still fails 😕
b
I am definitely able to repro your issue in the example repo though:
Copy code
ImportError: dlopen(/Users/krishnanchandra/.pex/installed_wheels/1cb99ef55a331a5f91f1ed691a232e14fe4ef5ca2334af00100be6baf35da287/PyMuPDF-1.23.26-cp311-none-macosx_11_0_arm64.whl/fitz/_extra.cpython-311-darwin.so, 0x0002): Library not loaded: @rpath/libmupdf.dylib
  Referenced from: <948BC1FA-DF38-3CE5-BAD2-8A12FE55521E> /Users/krishnanchandra/.pex/installed_wheels/1cb99ef55a331a5f91f1ed691a232e14fe4ef5ca2334af00100be6baf35da287/PyMuPDF-1.23.26-cp311-none-macosx_11_0_arm64.whl/fitz/_extra.cpython-311-darwin.so
1
p
I don't know much about how wheels work (new to python) so I'm having trouble determining if this is a
PyMuPDF
issue, a pants issue or a pex issue
my guess is that
PyMuPDF
is doing something non-standard that pants (or the pex packager) either doesn't support or needs configuration for
b
Haven’t figured it out yet but it seems like there is some historical precedent for the issue: https://github.com/lucasrla/remarks/issues/7
p
There is also this nix issue that seems suspiciously familiar (nix having to make special accommodations for this package)
b
Here’s a good clue towards the solution in the time I’ve spent so far - normally, in the broken installations of PyMuPDF, the installed wheel looks something like this:
Copy code
ls /Users/krishnanchandra/.pex/installed_wheels/71efe8cb3e0be4a9761976b9d0fd9cdc19abd44d490dcdf572858356e7157cde/PyMuPDF-1.23.11-cp312-none-macosx_11_0_arm64.whl/fitz/

__init__.py                  __pycache__                  _mupdf.so                    fitz.py                      table.py
__main__.py                  _extra.cpython-312-darwin.so extra.py                     mupdf.py                     utils.py
And a working installation looks like this:
Copy code
ls /System/Volumes/Data/Users/krishnanchandra/.pex/installed_wheels/1491c6899cc23f9e7ded9ded33c45d18c5cf9bfbe3a527968528845877dd81f3/PyMuPDFb-1.24.0-py3-none-macosx_11_0_arm64.whl/fitz/

libmupdf.dylib libmupdfcpp.so
1
p
aaaaha - so it's possible that their macos arm64 cpython wheel is broken
(I'm noting the difference between
cp312
and
py3
in the wheel names)
edit: on second read, py3 may be the name of an override that you have specified in python_sources.overrides?
b
Yeah, my environment also uses Python 3.12 while yours uses 3.11
👍 1
Versions for full clarity: macOS: 14.3.1 Python: 3.12.1
p
I'm testing with python 3.12.1, one sec
Copy code
No interpreter compatible with the requested constraints was found:

  Version matches CPython==3.12.1
er sorry, that's obviously an issue on my end
when I set my constraint to
interpreter_constraints = ["==3.12.*"]
, the build fails with the same dylib issue
I'm on 3.12.2, so slight difference
macos 14.2.1
I wonder where you got
PyMuPDFb-1.24.0-py3-none-macosx_11_0_arm64.whl
? I don't see it here: https://pypi.org/project/PyMuPDF/1.24.0/#files
(I downloaded the closest thing, https://files.pythonhosted.org/packages/a0/a7/ca30ad212dbf23ae37ea5f6c7b584fc5d547c6cd56[…]bd713b846/PyMuPDF-1.24.0-cp312-none-macosx_11_0_arm64.whl, and extracted its contents, but it has the "broken wheel" contents, not the "good wheel" contents containing the dylib.)
b
It’s because that package is for
PyMuPDFb
(Note the lower case b at the end). That’s the binary package that PyMuPDF depends on, and where the dynamic library file comes from: https://pypi.org/project/PyMuPDFb/1.24.0/#files It seems like the issue here is that PyMuPDFb is not being installed when it should be. One thing you could try is adding
PyMuPDFb==1.24.0
as well to the
requirements.txt
file and seeing if that changes things.
p
oof, that's subtle.
Haven't fixed it, going to pause troubleshooting for a bit. A few notes for posterity:
PyMuPDFb
automatically shows up in
defaults.lock
, so the transitive dep seems to be configured correctly. The linked `PyMuPDFb` wheel contains the correct dylib file. So the issue seems to be that
PyMuPDF
cannot "see" the dylib contained within its dependency
PyMuPDFb
. I'm not sure how to get the
PyMuPDFb
into the
dlopen
search path for
PyMuPDF
.
Thanks for your help, Krishnan!
b
Np! I’ve run into quite a few issues with PyMuPDF in the past so not surprised that it’s come up again…really surprising that I can’t repro the issue on my work repo, but that’s maybe for the best 😅
🤣 1
p
h
I've updated on that issue