5

I am trying to use openslide's python bindings (http://openslide.org/download/) and have tried just about everything with no success in being able to import openslide to Python 2.7. Here's my error message:

    >>> import openslide
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/usr/local/lib/python2.7/site-packages/openslide/__init__.py", line 29, in <module>
    from openslide import lowlevel
    File "/usr/local/lib/python2.7/site-packages/openslide/lowlevel.py", line 52, in <module>
    raise ImportError("Couldn't locate OpenSlide library")
    ImportError: Couldn't locate OpenSlide library

I have pip install openslide-python successfully, and it seems like it is being recognized by the recognition of line 29 and 52 in packages/openslide.

Any suggestions on how to proceed?

NoDataDumpNoContribution
  • 10,591
  • 9
  • 64
  • 104
  • I'm having a similar problem, except my error is "Couldn't locate OpenSlide dylib". Did you ever figure it out? – Bow Nov 02 '17 at 20:39

2 Answers2

2

You need to install the openslide library and dependencies, then the python package. Read for instructions for your OS here:

http://openslide.org/download/

marbel
  • 7,560
  • 6
  • 49
  • 68
0

This is known as "DLL Hell". There is a Windows DLL file that is taking precedence over the DLL file python needs in this source code. You need to prepend the PATH variable in your Python binding module before calling the C openslide library with the full path of the bin folder where the C openslide library DLL files reside. This will override the Windows "zlib1.dll" file by using the OpenSlide "zlib1.dll" file.

import os
openslide_path = os.getcwd() + "\\openslide-win64-20171122\\bin"
os.environ['PATH'] = openslide_path + ";" + os.environ['PATH']
from openslide import OpenSlide

The path indicated by openslide_path can be downloaded here. This is the OpenSlide C library.

https://openslide.org/download/

You also need to install the "openslide-python" package in your python environment.

JustBeingHelpful
  • 18,332
  • 38
  • 160
  • 245