본문 바로가기
CS/삽질로그

[Python] pyvips 모듈 임포트 오류 (OSError, ModuleNotFoundError)

by judy@ 2022. 8. 22.

 

pyvips 라이브러리 사용 시 아래와 같은 오류를 마주할 수 있다. 

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
~/anaconda3/envs/[ENV-NAME]/lib/python3.8/site-packages/pyvips/__init__.py in <module>
     18 try:
---> 19     import _libvips
     20 

ModuleNotFoundError: No module named '_libvips'

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
<ipython-input-10-a7ddf1d6bb42> in <module>
      4 import numpy as np
      5 
----> 6 import pyvips
      7 import matplotlib.pyplot as plt
      8 

~/anaconda3/envs/[ENV-NAME]/lib/python3.8/site-packages/pyvips/__init__.py in <module>
     69     # possibly use ctypes.util.find_library() to locate the lib?
     70     gobject_lib = ffi.dlopen(_gobject_libname)
---> 71     vips_lib = ffi.dlopen(_vips_libname)
     72     if _glib_libname:
     73         glib_lib = ffi.dlopen(_glib_libname)

~/anaconda3/envs/[ENV-NAME]/lib/python3.8/site-packages/cffi/api.py in dlopen(self, name, flags)
    148                             "or an already-opened 'void *' handle")
    149         with self._lock:
--> 150             lib, function_cache = _make_ffi_library(self, name, flags)
    151             self._function_caches.append(function_cache)
    152             self._libraries.append(lib)

~/anaconda3/envs/[ENV-NAME]/lib/python3.8/site-packages/cffi/api.py in _make_ffi_library(ffi, libname, flags)
    830 def _make_ffi_library(ffi, libname, flags):
    831     backend = ffi._backend
--> 832     backendlib = _load_backend_lib(backend, libname, flags)
    833     #
    834     def accessor_function(name):

~/anaconda3/envs/[ENV-NAME]/lib/python3.8/site-packages/cffi/api.py in _load_backend_lib(backend, name, flags)
    825         if first_error is not None:
    826             msg = "%s.  Additionally, %s" % (first_error, msg)
--> 827         raise OSError(msg)
    828     return backend.load_library(path, flags)
    829 

OSError: cannot load library 'libvips.so.42': libvips.so.42: cannot open shared object file: No such file or directory.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'libvips.so.42'

 

아래와 두 가지 방법을 활용하여 위 오류를 해결할 수 있다.

나의 경우, 어떤 os에서는 첫 번째 방법으로 해결 가능했고, 어떤 경우는 2까지 동원해야 했다.

 

방법1:

출처: https://github.com/libvips/pyvips/issues/86

conda install -c conda-forge librsvg
conda install -c conda-forge libiconv 

 

방법2:

출처: https://stackoverflow.com/questions/70849182/could-not-open-library-vips-42-could-not-open-library-libvips-42-dylib

# ubuntu
apt install libvips

# macOS
brew install vips
반응형