libvips / pyvips

python binding for libvips using cffi
MIT License
642 stars 49 forks source link

pyvips conflicts with openslide #231

Open itachi1232gg opened 3 years ago

itachi1232gg commented 3 years ago

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
jcupitt commented 3 years ago

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.

siemdejong commented 1 year ago

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}.")