pyvips icon indicating copy to clipboard operation
pyvips copied to clipboard

pyvips not running natively on M1 mac

Open jil24 opened this issue 1 year ago • 1 comments

importing a newly installed pyvips (via miniforge, native arm64 architecture) results in this error:

>>> import pyvips
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/Yashka/.miniforge3/envs/pyvips/lib/python3.10/site-packages/pyvips/__init__.py", line 145, in <module>
    _log_handler_cb = ffi.callback('GLogFunc', _log_handler_callback)
  File "/Users/Yashka/.miniforge3/envs/pyvips/lib/python3.10/site-packages/cffi/api.py", line 403, in callback
    return callback_decorator_wrap(python_callable)  # direct mode
  File "/Users/Yashka/.miniforge3/envs/pyvips/lib/python3.10/site-packages/cffi/api.py", line 396, in callback_decorator_wrap
    return self._backend.callback(cdecl, python_callable,
MemoryError: Cannot allocate write+execute memory for ffi.callback(). You might be running on a system that prevents this. For more information, see https://cffi.readthedocs.io/en/latest/using.html#callbacks

When i force an install of an x86_64 python, pyvips, and libvips and run them via emulation, everything works.

jil24 avatar Oct 14 '22 20:10 jil24

Hi @jil24,

pyvips supports two modes: API and ABI.

In API mode, it generates C source for the binding at install time (during the execution of setup.py) and uses that to link to the libvips binary, and to generate the callbacks it needs. This is the mode you need on macOS.

If ABI mode install fails (eg. perhaps no libvips headers, or no C compiler available), then it falls back to ABI mode. In ABI mode, it only uses the binary ABI supported by libvips, and (in effect) generates the wrapper at runtime. This is slower, and needs w+x mallocs. This mode is only really useful on Windows, where a C compiler is often missing.

tldr: You pyvips install didn't work correctly, probably because it couldn't find the libvips headers. I would check how you installed libvips, where the headers are, and if they are available to your python module installer.

If you used homebrew, it installs libraries to a non-standard location, and you'll need to set up your environment correctly before any non-homebrew build tool can see them.

jcupitt avatar Oct 15 '22 11:10 jcupitt