Reputation: 67
I'm facing a problem where I can't import pyvips as the OS doesn't find the directory where all the DLLs are located.
>>> import pyvips
Traceback (most recent call last):
File "C:\Users\istab\.virtualenvs\RPAS_DS_UI-v4ujo25h\lib\site-packages\pyvips\__init__.py", line 19, in <module>
import _libvips
ModuleNotFoundError: No module named '_libvips'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\istab\.virtualenvs\RPAS_DS_UI-v4ujo25h\lib\site-packages\pyvips\__init__.py", line 70, in <module>
gobject_lib = ffi.dlopen(_gobject_libname)
File "C:\Users\istab\.virtualenvs\RPAS_DS_UI-v4ujo25h\lib\site-packages\cffi\api.py", line 150, in dlopen
lib, function_cache = _make_ffi_library(self, name, flags)
File "C:\Users\istab\.virtualenvs\RPAS_DS_UI-v4ujo25h\lib\site-packages\cffi\api.py", line 832, in _make_ffi_library
backendlib = _load_backend_lib(backend, libname, flags)
File "C:\Users\istab\.virtualenvs\RPAS_DS_UI-v4ujo25h\lib\site-packages\cffi\api.py", line 828, in _load_backend_lib
return backend.load_library(path, flags)
OSError: cannot load library 'C:\Users\istab\RPAS_2\RPAS_DS_UI\vips-dev-8.13\bin\libgobject-2.0-0.dll': error 0x7e
I followed the documentation Here and added the bin folder to PATH
yet the same problem occurs. And it is not my first time having problems with packages' DLLs :')
Any thoughts?
Upvotes: 1
Views: 5284
Reputation: 41137
This is a duplicate of [SO]: PyWin32 and Python 3.8.0 (@CristiFati's answer), but i'm going to add some details.
[PyPI]: pyvips 2.2.1 (Non-conda install section) states:
To set
PATH
from within Python, you need something like this at the start:import os vipshome = 'c:\\vips-dev-8.7\\bin' os.environ['PATH'] = vipshome + ';' + os.environ['PATH']
Now when you import pyvips, it should be able to find the DLLs.
This is no longer correct (starting with Python 3.8 - check the 1st URL why).
But PyVIPS (v2.2.1 - latest at answer time) doesn't support Python 3.8 (highest is v3.6).
For Python 3.8+ compatibility (and also maintaining the old one), the above snippet should be (text would also need some changes):
import os
add_dll_dir = getattr(os, "add_dll_directory", None)
vipsbin = r"c:\vips-dev-8.7\bin" # LibVIPS binary dir
if callable(add_dll_dir):
add_dll_dir(vipsbin)
else:
os.environ["PATH"] = os.pathsep.join((vipsbin, os.environ["PATH"]))
import pyvips
Created [GitHub]: libvips/pyvips - Update install steps for Python 3.8+ to track this (fixed on 221003).
Might be useful to read:
[SO]: How PyCharm imports differently than system command prompt (Windows) (@CristiFati's answer)
[SO]: Discover missing module using command-line ("DLL load failed" error) (@CristiFati's answer)
Upvotes: 3
Reputation: 1
Does not seem to work anymore after forced company windows10 21H2 update. get: ModuleNotFoundError: No module named 'pyvips'
Even installed latest python:
C:\Users\maja>python
Python 3.11.1 (tags/v3.11.1:a7a450f, Dec 6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Even installed vips-dev-8.13
Is it a 32/64 bit problem?
For some reason, which was not working yesterday, pyvips does install!?
C:\Data\techtime\Houston>pip install pyvips
Collecting pyvips
Using cached pyvips-2.2.1.tar.gz (633 kB)
Preparing metadata (setup.py) ... done
Collecting cffi>=1.0.0
Using cached cffi-1.15.1-cp311-cp311-win_amd64.whl (179 kB)
Collecting pycparser
Using cached pycparser-2.21-py2.py3-none-any.whl (118 kB)
Installing collected packages: pycparser, cffi, pyvips
DEPRECATION: pyvips is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
Running setup.py install for pyvips ... done
Successfully installed cffi-1.15.1 pycparser-2.21 pyvips-2.2.1
Using proposed PATH include:
import os
add_dll_dir = getattr(os, "add_dll_directory", None)
vipsbin = r"c:\vips-dev-8.13\bin" # LibVIPS binary dir
if callable(add_dll_dir):
add_dll_dir(vipsbin)
else:
os.environ["PATH"] = os.pathsep.join((vipsbin, os.environ["PATH"]))
import pyvips as py
Now I get:
Traceback (most recent call last):
File "C:\Users\maja\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvips\__init__.py", line 19, in <module>
import _libvips
ModuleNotFoundError: No module named '_libvips'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Data\techtime\Houston\houston-compare-v2.py", line 15, in <module>
import pyvips as py
File "C:\Users\maja\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyvips\__init__.py", line 70, in <module>
gobject_lib = ffi.dlopen(_gobject_libname)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\maja\AppData\Local\Programs\Python\Python311\Lib\site-packages\cffi\api.py", line 150, in dlopen
lib, function_cache = _make_ffi_library(self, name, flags)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\maja\AppData\Local\Programs\Python\Python311\Lib\site-packages\cffi\api.py", line 832, in _make_ffi_library
backendlib = _load_backend_lib(backend, libname, flags)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\maja\AppData\Local\Programs\Python\Python311\Lib\site-packages\cffi\api.py", line 827, in _load_backend_lib
raise OSError(msg)
OSError: cannot load library 'libgobject-2.0-0.dll': error 0x7e. Additionally, ctypes.util.find_library() did not manage to locate a library called 'libgobject-2.0-0.dll'
Guess what's the solution: uninstalled python and installed v 3.6.8, then pyvips >>> works!
Upvotes: 0