Installing Openslide on a Windows 10 computer with Python 3.7

Neeraj Kumar Vaid
2 min readMar 8, 2021

--

In this post, we will learn how to install Openslide-Python on a computer with Microsoft Windows 10 operating system and Anaconda Python 3.7.

Openslide-Python is a popular Python module for reading whole slide images. Whole slide images are gigapixel multi-resolution images of tissue sections and are also known as digital (or virtual) slides in the computational pathology community. Due to their enormous size, whole slide images can not be read directly into computer’s memory using standard Python libraries. Openslide provides the flexibility of loading small patches of these digital slides at the required resolution level. OpenSlide can read virtual slides in several formats including:

Steps to install Openslide-Python on a Windows 10 platform with Anaconda Python 3.7 are as follows:

  1. Download Microsoft Visual Studio IDE (Community 2019 edition) from https://visualstudio.microsoft.com/
  2. Click on the vs_community.exe file in the Downloads folder and follow the on-screen instructions. Make sure you check Desktop Development with C++ under Windows and Python Development under Web & Cloud tabs. Also check MSVC 140 under the Optional tab in Summary.
  3. Restart your computer after installing the visual studio.
  4. Download Openslide-Python package, by clicking at the clone or download option (green button), from the following github page: https://github.com/openslide/openslide-python
  5. Unzip the downloaded Openslide-Python package.
  6. Open Anaconda Prompt and change the directory to the unzipped Openslide-Python folder.
  7. Run the command: python set-up.py install
  8. Download Openslide Windows binaries from the following webpage: https://openslide.org/download/
  9. Unzip the windows binaries folder and keep it at the location of your choice.
  10. Go to the following folder on your computer and open lowlevel.py in a text editor: C:\Users\Gan\AppData\Local\Continuum\anaconda3\Lib\site-packages\openslide
  11. Add the following commands at the beginning of lowlevel.py file:

import os

os.environ[‘PATH’] = “path-to-openslide-bin” + “;” + os.environ[‘PATH’]

Replace path-to-openslide-bin with the path of the bin folder within windows binaries file saved at step 9 (keep the quotes). After these additions, save and close lowlevel.py file.

Now type python in your Anaconda Prompt and type import openslide to start using your newly installed module.

Sometimes import openslide will throw SyntaxError: (unicode error). To resolve this just put one more backslash before each backslash in path-to-openslide-bin so that C\Users\openslide-binaries\bin looks like C\\Users\\openslide-binaries\\bin.

--

--

Neeraj Kumar Vaid
Neeraj Kumar Vaid

Written by Neeraj Kumar Vaid

Applied machine learning researcher | Love Books

Responses (3)