pyvips icon indicating copy to clipboard operation
pyvips copied to clipboard

pyvips conflicts with openslide

Open itachi1232gg opened this issue 5 years ago • 2 comments

Hello, I'm doing a project using both pyvips and openslide, but I cannot import them at the same time. It's possibly due to conflicts between some dynamic link libraries used in pyvips and openslide. I tried this, but it doesn't work, still cannot locate some dll files.

dir = os.path.dirname( os.path.abspath(__file__))
os.environ["PATH"] = dir + "\\vips;" + os.environ["PATH"]
print(os.environ['PATH'])
import pyvips

itachi1232gg avatar Jan 25 '21 11:01 itachi1232gg

Hello @itachi1232gg,

I guess this is on Windows? Yes, you can't use openslide and pyvips at the same time on that platform without a lot of work. You can use both on WSL2, if that's an option.

Why do you need openslide? I think you should be able to do everything in pyvips.

jcupitt avatar Jan 25 '21 11:01 jcupitt

If anyone comes across this, my best solution is to make an install_windows function that can be called in any module.

Pyvips and OpenSlide Python are needed: pip install pyvips pip install openslide-python

Vips has to be extracted somewhere.

import os
import platform

def install_windows(vipsbin: str):
    """Install pyvips and openslide for windows.

    Requests vips, such that it can import pyvips [1] and openslide [2] in the right order.

    Vips must be installed separately for Windows. Vips already includes OpenSlide.
    Provide the path to vips/bin.

    Parameters
    ----------
    vipsbin : str
        `path/to/vips/bin`.

    Examples
    --------
    >>> install_windows("D:/apps/vips-dev-8.14/bin")

    References
    ----------
    [1] https://github.com/libvips/pyvips
    [2] https://openslide.org/
    """
    assert platform.system() == "Windows", "install_windows() is for Windows only."

    os.environ["PATH"] = vipsbin + ";" + os.environ["PATH"]

    try:
        # NOTE: first pyvips, than openslide.
        import pyvips  # noqa:F401 isort:skip
        import openslide  # noqa:F401
    except OSError:
        raise ImportError(f"Please check if vips is installed at {vipsbin}.")

siemdejong avatar Feb 21 '23 12:02 siemdejong