PyMuPDF icon indicating copy to clipboard operation
PyMuPDF copied to clipboard

Support for nix-darwin

Open G3zz opened this issue 2 years ago • 4 comments

Is your feature request related to a problem? Please describe. It is not possible to use pymupdf installed via pip with a mupdf installed through nix-darwin without creating symlinks to mupdf outside of the nix store.

Describe the solution you'd like The ability for setup.py on darwin to check for the existence of nix-darwin and scan the nix store for the installed mupdf binaries. I suppose this could be something as simple as using an environment variable.

Describe alternatives you've considered It is possible to to install pymupdf through nix packages too, but this is not ideal for co-working with colleagues who do not use nix.

G3zz avatar May 10 '22 16:05 G3zz

I don't use MacOS and i don't know what nix-darwin is, so i might be making some basic mistakes here.

PyMuPDF wheels come with MuPDF already linked in, and MacOS wheels for the latest release, PyMuPDF-1.20.0, are on pypi.org for use by pip. Are these MacOS wheels suitable for your system?

If suitable wheels are not available, pip will install by building from an sdist. As of PyMuPDF-1.20.0, the sdist will contain source for mupdf which will be built into pymupdf automatically. Does this behaviour work for you?

Finally if you install directly from a git checkout of PyMuPDF with setup.py install, it will default to download MuPDF source for building into PyMuPDF.

If you want to prevent the default use of the hard-coded mupdf, you should build with PYMUPDF_SETUP_MUPDF_BUILD set to an empty string. E.g. PYMUPDF_SETUP_MUPDF_BUILD= setup.py install. This will set some defaults for the include paths, library paths and library names, such as looking for headers in /usr/local/include, libraries in /usr/local/lib and linking with libraries called mupdf and mupdf-third; the intention here is to use a system-installed mupdf.

Currently there is no way to override these defaults. But it should be possible to add support for new environmental variables that force particular include path, library path and library names. Alternatively you could modify setup.py around line 596 include_dirs.append("/usr/local/include/mupdf") to get the behaviour you require, and these changes could be incorporated into the PyMuPDF tree in future (note that submitted patches must have a signed contributor license agreement). Please let me know whether either of these options could work for you.

Closing this because no response for 8 weeks.

Sorry for the delay on this - I got sidetracked with other things. Thanks very much for your reply, I tried modifying setup.py to point to the mupdf include directories, but the import fitz would complain that _jpeg_resync_to_restart was not found. It looks like a linking issue to me with libjpeg (which in Nix) is installed in a non-standard location. Presumably I need to add libjpeg to the library_dirs list?

G3zz avatar Sep 14 '22 09:09 G3zz

Welcome back.

I think to make progress here, i'll need you to post the following:

  • The full output from pip install mupdfpy.
  • The diff that you have applied to PyMuPDF's setup.py.
  • The exact command you are using to build PyMuPDF.
  • The full output from your build of PyMuPDF.
  • The full output when you attempt to import mupdf from Python.

Hi @julian-smith-artifex-com @G3zz, I give a solution which works for me on macOS Apple Chip (this manner works for Intel too) in #2012 . Hope it helps !

tikitong avatar Nov 02 '22 00:11 tikitong

MacOS/ARM wheels have been available since PyMuPDF-1.21.0, released 2022-11-8.