【openslide-python安装】Linux、Windows安装openslide-python

Linux安装openslide-python

    • 1. Linux环境安装openslide-python
  • Linux提示Unable to locate package该如何处理?
    • 2. Windows环境安装openslide-python

1. Linux环境安装openslide-python

Linux环境相对比较简单,两行命令搞定:

apt install python-openslide    #针对ubuntu,其他系统没测试过
pip install Openslide-python   #pip 安装在这里插入代码片

但是,我在执行的时候出现错误:
Unable to locate package python-slide
执行“apt install python-openslide”出现的错误
此时说明你的系统镜像源不包含“python-openslide"的安装包。

Linux提示Unable to locate package该如何处理?

此时我们需要更新国内apt-get镜像源
1. 备份sources.list文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
2. 打开sources.list文件
sudo gedit /etc/apt/sources.list
3. 删除原有内容,添加一下内容
#清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
     
#阿里云源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse 

这两个源都可以用,我都试过,感觉阿里云源速度更快。

  1. 更新
    保存sources.list文件后需要更新apt-get。
sudo apt-get update

参考:https://blog.csdn.net/sunzhanl/article/details/121199726

然后再按照前面的步骤安装 python-openslide。

2. Windows环境安装openslide-python

windows环境下的安装略显复杂。

  1. 首先,到openslide官网下载对应的windows二进制包。

openslide官网
【openslide-python安装】Linux、Windows安装openslide-python_第1张图片
3. 其次,将安装包解压到一个文件夹中,并将该文件夹的bin目录和lib目录添加到环境变量。
【此电脑】右键——【属性】——【高级系统设置】——【环境变量】——【xx的用户变量】——【Path】
【openslide-python安装】Linux、Windows安装openslide-python_第2张图片
3. 执行命令进行安装

pip install Openslide-python   #pip 安装

到此,在import openslide时可能会遇到一下报错:

Python 3.6.10 |Anaconda, Inc.| (default, May  7 2020, 19:46:08) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import openslide
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "d:\ProgramData\Anaconda3\envs\path\lib\site-packages\openslide\__init__.py", line 29, in <module>
    from openslide import lowlevel
  File "d:\ProgramData\Anaconda3\envs\path\lib\site-packages\openslide\lowlevel.py", line 44, in <module>
    _lib = cdll.LoadLibrary('libopenslide-0.dll')
  File "d:\ProgramData\Anaconda3\envs\path\lib\ctypes\__init__.py", line 426, in LoadLibrary
    return self._dlltype(name)
  File "d:\ProgramData\Anaconda3\envs\path\lib\ctypes\__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] 找不到指定的模块。

这个错误是因为python搜索的bin库里没有找到相应的dll,所以需要做如下操作:
找到openslide文件夹下面的lowlevel.py文件

d:\ProgramData\Anaconda3\envs\path\lib\site-packages\openslide\lowlevel.py

在lowlevel.py下面增加如下代码:

import os

# openslide-bin-path为 openslide 的bin文件夹绝对路径。
os.environ['PATH'] = "openslide-bin-path" + ";" + os.environ['PATH']   

# 例如: 
os.environ['PATH'] = "D:\\openslide-win64-20171122\\bin" + ";" + os.environ['PATH']  

就此,完成Windows下的Openslide-python安装。

参考:https://blog.csdn.net/lichao0627/article/details/106468228

你可能感兴趣的:(linux,python,windows)