libvips / pyvips

python binding for libvips using cffi
MIT License
615 stars 50 forks source link

Getting pyvips to work on Mac with python 3.7.7 #362

Open gregster7 opened 1 year ago

gregster7 commented 1 year ago

I have installed pyvips using pip on python 3.7.7 virtual environment. When I try to load an svs image at {{PATH_TO_FILE}} I get:

Python 3.7.7 (default, Mar 23 2020, 17:31:31)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyvips
>>> slide = pyvips.Image.new_from_file({{PATH_TO_FILE}})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/disco/Sandbox/2020_11_django/HemeLabel/HemeLabel_env/lib/python3.7/site-packages/pyvips/vimage.py", line 349, in new_from_file
    raise Error('unable to load from file {0}'.format(vips_filename))
pyvips.error.Error: unable to load from file b'"{{PATH_TO_FILE}}'
  VipsForeignLoad: file "{{PATH_TO_FILE}}" does not exist

Not sure what to do next. Cannot install a different version of python as this is part of a large existing application.

jcupitt commented 1 year ago

Hi @gregster7,

Have you installed the libvips binary? Homebrew is probably the simplest way to do this on mac.

You can verify that you have openslide enabled with:

$ vips --vips-config | grep -i opensl
OpenSlide load: true (dynamic module: true)

And verify that pyvips found the libvips headers with:

 $ python3
Python 3.10.6 (main, Nov  2 2022, 18:53:38) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyvips
>>> pyvips.API_mode
True
>>> 

You might need to set PKG_CONFIG_PATH before installing with pip to get it to see the libvips headers.

gregster7 commented 1 year ago

Hi @jcupitt

Thank you for the help. Dynamic module is not enabled. Do I need to enable this 'dynamic module' and if so how?

vips --vips-config | grep -i opensl
OpenSlide load: yes (dynamic module: no)

The rest seems correct:

Python 3.7.7 (default, Mar 23 2020, 17:31:31)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyvips
>>> pyvips.API_mode
True

Thank you!

jcupitt commented 1 year ago

No dynamic modules is fine. It sounds like everything is working, hooray!

jcupitt commented 1 year ago

Wait, you have openslide, but can't load SVS?

Something screwy is happening, perhaps you have several libvips installed and it's picking up the wrong one when running inside your app? Maybe try:

slide = pyvips.Image.openslideload("testfile.svs")

And see what happens.

gregster7 commented 1 year ago
>>> import pyvips
>>> slide = pyvips.Image.openslideload("testfile.svs")

(process:66755): GLib-CRITICAL **: 13:49:15.942: g_datalist_id_set_data_full: assertion 'key_id > 0' failed

(process:66755): GLib-GObject-CRITICAL **: 13:49:15.942: g_param_spec_pool_lookup: assertion 'pool != NULL' failed

(process:66755): GLib-GObject-WARNING **: 13:49:15.942: g_object_set_is_valid_property: object class '(null)' has no property named 'filename'
Traceback (most recent call last):
  File "vips_py_test.py", line 3, in <module>
    slide = pyvips.Image.openslideload("testfile.svs")
  File "/Users/disco/Sandbox/2020_11_django/HemeLabel/HemeLabel_env/lib/python3.7/site-packages/pyvips/vimage.py", line 256, in call_function
    return pyvips.Operation.call(name, *args, **kwargs)
  File "/Users/disco/Sandbox/2020_11_django/HemeLabel/HemeLabel_env/lib/python3.7/site-packages/pyvips/voperation.py", line 305, in call
    raise Error('unable to call {0}'.format(operation_name))
pyvips.error.Error: unable to call openslideload
  openslideload: parameter filename not set
jcupitt commented 1 year ago

Hmm maybe the openslide loader isn't being initialised? What libvips version is that, and where did you get the binary?

gregster7 commented 1 year ago

Not sure where I got the binary - I am guessing I installed it with Brew. installed it for command line a few years ago and have happily been using it ever since without problems.

vips-8.12.2

pyvips==2.2.1

vips --vips-config enable debug: no enable deprecated library components: yes enable modules: no use fftw3 for FFT: yes accelerate loops with orc: yes ICC profile support with lcms: yes (lcms2) zlib: yes text rendering with pangocairo: yes font file support with fontconfig: yes RAD load/save: yes Analyze7 load/save: yes PPM load/save: yes GIF load: yes GIF save with cgif: yes EXIF metadata support with libexif: yes JPEG load/save with libjpeg: yes (pkg-config) JXL load/save with libjxl: yes (dynamic module: no) JPEG2000 load/save with libopenjp2: yes PNG load with libspng: yes PNG load/save with libpng: yes (pkg-config libpng >= 1.2.9) quantisation to 8 bit: yes TIFF load/save with libtiff: yes (pkg-config libtiff-4) image pyramid save: yes HEIC/AVIF load/save with libheif: yes (dynamic module: no) WebP load/save with libwebp: yes PDF load with PDFium: no PDF load with poppler-glib: yes (dynamic module: no) SVG load with librsvg-2.0: yes EXR load with OpenEXR: yes OpenSlide load: yes (dynamic module: no) Matlab load with matio: yes NIfTI load/save with niftiio: no FITS load/save with cfitsio: yes Magick package: MagickCore (dynamic module: no) Magick API version: magick7 load with libMagickCore: yes save with libMagickCore: yes