Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional dependency on pyvips-binary #507

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kleisauke
Copy link
Member

@kleisauke kleisauke commented Sep 21, 2024

Allowing users to install pyvips with binary packages via:

$ pip install "pyvips[binary]"

See: https://pypi.org/project/pyvips-binary/.

Marked as draft due to this notes:

@jcupitt
Copy link
Member

jcupitt commented Sep 22, 2024

Nice!

Yes, maybe a separate repo is better.

Allowing users to install pyvips with binary packages via:
pip install "pyvips[binary]"

See: https://pypi.org/project/pyvips-binary/.
@kleisauke kleisauke changed the title Add pyvips-binary package Add optional dependency on pyvips-binary Sep 23, 2024
@kleisauke
Copy link
Member Author

Done!

https://pypi.org/project/pyvips-binary/
https://github.com/kleisauke/pyvips-binary

@kleisauke
Copy link
Member Author

... here are some testing notes:

$ pkg-config --exists --print-errors vips
Package vips was not found in the pkg-config search path.
Perhaps you should add the directory containing `vips.pc'
to the PKG_CONFIG_PATH environment variable
Package 'vips', required by 'virtual:world', not found
$ pip3 install pyvips
$ python -c "import pyvips; print(pyvips.API_mode)"
ModuleNotFoundError: No module named '_libvips'

During handling of the above exception, another exception occurred:

[...]

OSError: cannot load library 'libvips.so.42': libvips.so.42: cannot open shared object file: No such file or directory.

[...]
$ pip3 install pyvips-binary
$ python -c "import pyvips; print(pyvips.API_mode)"
True
$ python -c "import pyvips; pyvips.Image.black(1024, 1024).write_to_file('x.jpg')"
$ file x.jpg
x.jpg: JPEG image data, Exif standard: [TIFF image data, little-endian, direntries=6, orientation=upper-left, xresolution=86, yresolution=94, resolutionunit=2], baseline, precision 8, 1024x1024, components 1

@jcupitt
Copy link
Member

jcupitt commented Sep 24, 2024

Ah fantastic! That's so cool. I'll test here as well.

Shall we put you on the authors list as well? What email addr would you prefer?

@jcupitt
Copy link
Member

jcupitt commented Sep 24, 2024

Is is possible to invert the sense of this option? I'm sure most people should use the netvips binaries rather than the system ones.

So pip install pyvips has the pyvips-binary dependency, and pip install pyvips[system] (something like that?) will use the system libvips.

@kleisauke
Copy link
Member Author

Shall we put you on the authors list as well? What email addr would you prefer?

Feel free to add me to the authors list! I usually use the same email address that's on my GitHub profile.
https://github.com/kleisauke/pyvips-binary/blob/deaf1bf1c360e400f8b7b7869d05c4e695c2b4e5/pyproject.toml#L17

Is is possible to invert the sense of this option? I'm sure most people should use the netvips binaries rather than the system ones.

I had the same thought, but it doesn't seem to be possible at the moment. This future possible enhancement is discussed in detail here: https://discuss.python.org/t/4898.

@jcupitt
Copy link
Member

jcupitt commented Sep 24, 2024

Maybe we could just make another pyvips package (pyvips-system?) without a dependency on pyvips-binary?

@kleisauke
Copy link
Member Author

That approach might work, but I'm uncertain if it's the best option for users who prefer relying on system binaries.

For example, Zulip tends to favor using libvips from the package manager (see e.g. commit zulip/zulip@e8f7e28). Additionally, pyvips is commonly used by users who process whole-slide images, something that the pyvips-binary dependency doesn't support (since it uses the -web variant).

The pyvips-binary package also lacks pre-built wheels for less common architectures (such as linux-riscv64, linux-ppc64le, win32-arm64, etc.) and only supports CPython.

Perhaps we should consider catching the OSError mentioned above and re-throwing it with a message suggesting that the optional [binary] package might need to be installed? sharp handles this elegantly, see for example:

Details
node_modules\sharp\lib\sharp.js:114
  throw new Error(help.join('\n'));
        ^

Error: Could not load the "sharp" module using the win32-arm64 runtime
Possible solutions:
- Manually install libvips >= 8.15.3
- Add experimental WebAssembly-based dependencies:
    npm install --cpu=wasm32 sharp
    npm install @img/sharp-wasm32
- Consult the installation documentation:
    See https://sharp.pixelplumbing.com/install
    at Object.<anonymous> (node_modules\sharp\lib\sharp.js:114:9)
    at Module._compile (node:internal/modules/cjs/loader:1460:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1544:10)
    at Module.load (node:internal/modules/cjs/loader:1275:32)
    at Module._load (node:internal/modules/cjs/loader:1091:12)
    at wrapModuleLoad (node:internal/modules/cjs/loader:212:19)
    at Module.require (node:internal/modules/cjs/loader:1297:12)
    at require (node:internal/modules/helpers:123:16)
    at Object.<anonymous> (node_modules\sharp\lib\constructor.js:10:1) 
    at Module._compile (node:internal/modules/cjs/loader:1460:14)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants