Installing openslide-python

I’m trying to install openslide-python via pip_install to support reading NRRD files with @MONAI. I am getting the following error with Slicer 5.0.2 on Linux:

>>> pip_install('openslide-python')
Collecting openslide-python
  Using cached openslide-python-1.2.0.tar.gz (338 kB)
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'done'
Requirement already satisfied: Pillow in ./lib/Python/lib/python3.9/site-packages (from openslide-python) (9.0.1)
Building wheels for collected packages: openslide-python
  Building wheel for openslide-python (setup.py): started
  Building wheel for openslide-python (setup.py): finished with status 'error'
  error: subprocess-exited-with-error

  � python setup.py bdist_wheel did not run successfully.
  ? exit code: 1
  ??> [16 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-3.9
      creating build/lib.linux-x86_64-3.9/openslide
      copying openslide/__init__.py -> build/lib.linux-x86_64-3.9/openslide
      copying openslide/_version.py -> build/lib.linux-x86_64-3.9/openslide
      copying openslide/lowlevel.py -> build/lib.linux-x86_64-3.9/openslide
      copying openslide/deepzoom.py -> build/lib.linux-x86_64-3.9/openslide
      running build_ext
      building 'openslide._convert' extension
      creating build/temp.linux-x86_64-3.9
      creating build/temp.linux-x86_64-3.9/openslide
      /opt/rh/devtoolset-7/root/usr/bin/gcc -pthread -std=c99 -Wall -Wstrict-prototypes -fno-strict-aliasing -fwrapv -g -fPIC -I/home/sara/Slicer_stable/Slicer-5.0.2-linux-amd64/lib/Python/include/python3.9 -c openslide/_convert.c -o build/temp.linux-x86_64-3.9/openslide/_convert.o
      error: command '/opt/rh/devtoolset-7/root/usr/bin/gcc' failed: No such file or directory
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for openslide-python
  Running setup.py clean for openslide-python
Failed to build openslide-python
Installing collected packages: openslide-python
  Running setup.py install for openslide-python: started
  Running setup.py install for openslide-python: finished with status 'error'
  error: subprocess-exited-with-error

  � Running setup.py install for openslide-python did not run successfully.
  ? exit code: 1
  ??> [18 lines of output]
      running install
      /home/sara/Slicer_stable/Slicer-5.0.2-linux-amd64/lib/Python/lib/python3.9/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-3.9
      creating build/lib.linux-x86_64-3.9/openslide
      copying openslide/__init__.py -> build/lib.linux-x86_64-3.9/openslide
      copying openslide/_version.py -> build/lib.linux-x86_64-3.9/openslide
      copying openslide/lowlevel.py -> build/lib.linux-x86_64-3.9/openslide
      copying openslide/deepzoom.py -> build/lib.linux-x86_64-3.9/openslide
      running build_ext
      building 'openslide._convert' extension
      creating build/temp.linux-x86_64-3.9
      creating build/temp.linux-x86_64-3.9/openslide
      /opt/rh/devtoolset-7/root/usr/bin/gcc -pthread -std=c99 -Wall -Wstrict-prototypes -fno-strict-aliasing -fwrapv -g -fPIC -I/home/sara/Slicer_stable/Slicer-5.0.2-linux-amd64/lib/Python/include/python3.9 -c openslide/_convert.c -o build/temp.linux-x86_64-3.9/openslide/_convert.o
      error: command '/opt/rh/devtoolset-7/root/usr/bin/gcc' failed: No such file or directory
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

� Encountered error while trying to install package.
??> openslide-python

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
WARNING: You are using pip version 22.0.3; however, version 22.1.2 is available.
You should consider upgrading via the '/home/sara/Slicer_stable/Slicer-5.0.2-linux-amd64/bin/./python-real -m pip install --upgrade pip' command.
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/sara/Slicer_stable/Slicer-5.0.2-linux-amd64/bin/Python/slicer/util.py", line 3431, in pip_install
    _executePythonModule('pip', args)
  File "/home/sara/Slicer_stable/Slicer-5.0.2-linux-amd64/bin/Python/slicer/util.py", line 3394, in _executePythonModule
    logProcessOutput(proc)
  File "/home/sara/Slicer_stable/Slicer-5.0.2-linux-amd64/bin/Python/slicer/util.py", line 3363, in logProcessOutput
    raise CalledProcessError(retcode, proc.args, output=proc.stdout, stderr=proc.stderr)
subprocess.CalledProcessError: Command '['/home/sara/Slicer_stable/Slicer-5.0.2-linux-amd64/bin/../bin/PythonSlicer', '-m', 'pip', 'install', 'openslide-python']' returned non-zero exit status 1.

It seems there is a gcc binary it cannot find. This is working on Windows OS with no issues. I would appreciate any advice.

It builds the whl from source successfully? Or just not an issue on Windows because it uses the pre-built whl from PyPI?

openslide_python-1.2.0-cp39-cp39-win_amd64.whl

Are you able to successfully build on Ubuntu in regular python (not Slicer python)?

Some openslide-python issues related to building/whls on Linux.

On Windows, OpenSlide Python package requires manual installation of OpenSlide binaries. I’ve implemented that in BigImageViewer extension.

On Linux, you need to install libopenslide.

It is all somewhat hacky. It’ll be better to switch to OME-NGFF, a zarr-based big image (and transform, etc) file format.

Yes, it looks like this is the case.

Thanks @lassoan, given these OpenSlide build issues, I’m going to switch to another solution.

Keep us updated. Slicer will support the NGFF file format, probably using ome-zarr Python package. It would be great if you could use this format and experiment with the ome-zarr package.

1 Like

In case you didn’t see it here’s an example using the ome-zarr package. It’s pretty nice.

2 Likes

I though one of the benefits of the zarr was the support of the image pyramids. This imported file only seemed to display one of the resolution levels (as far as I can tell)?

Yes - the example is a bit arbitrary. The original dataset is multi-channel, 3D+T, and pyramid encoded and I just picked a particular resolution/timepoint/channel to display. All the other options can be exposed as we see fit, such as extracting a high-res subvolume and mapping any three channels to RGB (or a more complex mapping). The ome-zarr library supports all these options and we need to figure out a good interface for that.