ubuntu18安装python接口的openslide过程和错误整理

目录

  • 配置
  • 安装过程
    • pip直接安装
    • 安装openslide依赖:
    • 换源
    • 继续安装openslide-tools
    • 安装python-openslide
    • 添加适用于ubuntu版本的PPA
    • 安装python-openslide
    • python降级
    • 安装依赖库
    • 手动配置依赖库
  • 成功安装的方法

配置

版本
python 3.6.10
pip 20.1

安装过程

pip直接安装

pip install openslide-python

出现问题:

ERROR: Command errored out with exit status 1:
     command: /media/s2/cyq/anaconda3/envs/keras/bin/python3.6 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-kpd80yg0/openslide-python/setup.py'"'"'; __file__='"'"'/tmp/pip-install-kpd80yg0/openslide-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-86l6dxk_
         cwd: /tmp/pip-install-kpd80yg0/openslide-python/
    Complete output (5 lines):
    Traceback (most recent call last):
      File "", line 1, in 
      File "/tmp/pip-install-kpd80yg0/openslide-python/setup.py", line 2, in 
        from setuptools import setup, Extension, Feature
    ImportError: cannot import name 'Feature'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

安装openslide依赖:

sudo apt install python-opendslide

还是一样的问题

试了几种办法都不管用(包括升级python版本,重新搭一个虚拟环境等),最后选择用tar.gz安装

openslide下载网址:OpenSlide
ubuntu18安装python接口的openslide过程和错误整理_第1张图片
选择python接口下载,我选择的最新版本1.1.1
ubuntu18安装python接口的openslide过程和错误整理_第2张图片上传到集群,解压:
tar -xzvf openslide-python-1.1.1.tar.gz
进入文件夹:
cd openslide-python-1.1.1/
安装:
python setup.py install --single-version-externally-managed --record /dev/null
出现错误:

Traceback (most recent call last):
  File "setup.py", line 2, in 
    from setuptools import setup, Extension, Feature
ImportError: cannot import name 'Feature' from 'setuptools' (/media/s2/cyq/anaconda3/envs/test/lib/python3.8/site-packages/setuptools/__init__.py)

解决办法:降低setuptools版本(原来是46.3.1)
pip install setuptools==45
再次安装:
python setup.py install --single-version-externally-managed --record /dev/null
出现信息:

……
running install_egg_info
running egg_info
writing openslide_python.egg-info/PKG-INFO
writing dependency_links to openslide_python.egg-info/dependency_links.txt
writing requirements to openslide_python.egg-info/requires.txt
writing top-level names to openslide_python.egg-info/top_level.txt
reading manifest file 'openslide_python.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'openslide_python.egg-info/SOURCES.txt'
Copying openslide_python.egg-info to /media/s2/cyq/anaconda3/envs/test/lib/python3.8/site-packages/openslide_python-1.1.1-py3.8.egg-info
running install_scripts
writing list of installed files to '/dev/null'

测试,结果报错:

(test) cyq@node5-SYS-4029GP-TRT:~/openslide-python-1.1.1$ python
Python 3.8.2 | packaged by conda-forge | (default, Apr 24 2020, 08:20:52) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import openslide
Traceback (most recent call last):
  File "", line 1, in <module>
  File "/media/s2/cyq/openslide-python-1.1.1/openslide/__init__.py", line 29, in <module>
    from openslide import lowlevel
  File "/media/s2/cyq/openslide-python-1.1.1/openslide/lowlevel.py", line 58, in <module>
    _lib = cdll.LoadLibrary('libopenslide.so.0')
  File "/media/s2/cyq/anaconda3/envs/test/lib/python3.8/ctypes/__init__.py", line 451, in LoadLibrary
    return self._dlltype(name)
  File "/media/s2/cyq/anaconda3/envs/test/lib/python3.8/ctypes/__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libopenslide.so.0: cannot open shared object file: No such file or directory
>>> 

上网查了说是缺少依赖,需要安装:
sudo apt-get install openslide-tools
报错:

root@node5-SYS-4029GP-TRT:~# sudo apt-get install openslide-tools
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libopenjp2-7 libopenslide0
Suggested packages:
  libtiff-tools
The following NEW packages will be installed:
  libopenjp2-7 libopenslide0 openslide-tools
0 upgraded, 3 newly installed, 0 to remove and 201 not upgraded.
Need to get 141 kB/237 kB of archives.
After this operation, 696 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Ign:1 http://cn.archive.ubuntu.com/ubuntu disco-updates/universe amd64 libopenjp2-7 amd64 2.3.0-2build0.19.04.1
Err:1 http://security.ubuntu.com/ubuntu disco-updates/universe amd64 libopenjp2-7 amd64 2.3.0-2build0.19.04.1
  404  Not Found [IP: 91.189.91.39 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/universe/o/openjpeg2/libopenjp2-7_2.3.0-2build0.19.04.1_amd64.deb  404  Not Found [IP: 91.189.91.39 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

按照提示:
apt-get update
报错:

root@node5-SYS-4029GP-TRT:~# apt-get update
Ign:1 http://cn.archive.ubuntu.com/ubuntu disco InRelease                      
Ign:2 http://security.ubuntu.com/ubuntu disco-security InRelease               
Ign:3 http://cn.archive.ubuntu.com/ubuntu disco-updates InRelease
Hit:4 http://ppa.launchpad.net/graphics-drivers/ppa/ubuntu disco InRelease
Err:5 http://security.ubuntu.com/ubuntu disco-security Release
  404  Not Found [IP: 91.189.88.152 80]
Ign:6 http://cn.archive.ubuntu.com/ubuntu disco-backports InRelease
Err:7 http://cn.archive.ubuntu.com/ubuntu disco Release
  404  Not Found [IP: 91.189.91.39 80]
Err:8 http://cn.archive.ubuntu.com/ubuntu disco-updates Release
  404  Not Found [IP: 91.189.91.39 80]
Err:9 http://cn.archive.ubuntu.com/ubuntu disco-backports Release
  404  Not Found [IP: 91.189.91.39 80]
Reading package lists... Done
E: The repository 'http://security.ubuntu.com/ubuntu disco-security Release' no longer has a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: The repository 'http://cn.archive.ubuntu.com/ubuntu disco Release' no longer has a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: The repository 'http://cn.archive.ubuntu.com/ubuntu disco-updates Release' no longer has a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: The repository 'http://cn.archive.ubuntu.com/ubuntu disco-backports Release' no longer has a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.


换源

  1. 获取权限:
    sudo su
  2. 进入文件夹
    cd /etc/apt/
  3. 备份源:
    cp sources.list sources.list.bk
  4. 打开文件sources.list
    vim sources.list
  5. 换源1
    将文件内的内容改为:
deb http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse ##测试版源
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-proposed main restricted universe multiverse # 源码
deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse ##测试版源
deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-proposed main restricted universe multiverse

注:没有用清华源,是一个不知道什么的源

继续安装openslide-tools

指令sudo apt-get install openslide-tools
报错:

root@node5-SYS-4029GP-TRT:/etc/apt# sudo apt-get install openslide-tools 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libopenjpeg5 libopenslide0 libpng12-0
Suggested packages:
  libtiff-tools
The following NEW packages will be installed:
  libopenjpeg5 libopenslide0 libpng12-0 openslide-tools
0 upgraded, 4 newly installed, 0 to remove and 40 not upgraded.
Need to get 305 kB of archives.
After this operation, 1,098 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://cn.archive.ubuntu.com/ubuntu xenial/universe amd64 libopenjpeg5 amd64 1:1.5.2-3.1 [104 kB]
Get:2 http://cn.archive.ubuntu.com/ubuntu xenial-security/main amd64 libpng12-0 amd64 1.2.54-1ubuntu1.1 [116 kB]
Get:3 http://cn.archive.ubuntu.com/ubuntu xenial/universe amd64 libopenslide0 amd64 3.4.0-1build1 [70.9 kB]
Get:4 http://cn.archive.ubuntu.com/ubuntu xenial/universe amd64 openslide-tools amd64 3.4.0-1build1 [13.9 kB]
Fetched 305 kB in 3s (121 kB/s)        
Selecting previously unselected package libopenjpeg5:amd64.
(Reading database ... 215346 files and directories currently installed.)
Preparing to unpack .../libopenjpeg5_1%3a1.5.2-3.1_amd64.deb ...
Unpacking libopenjpeg5:amd64 (1:1.5.2-3.1) ...
Selecting previously unselected package libpng12-0:amd64.
Preparing to unpack .../libpng12-0_1.2.54-1ubuntu1.1_amd64.deb ...
Unpacking libpng12-0:amd64 (1.2.54-1ubuntu1.1) ...
dpkg: error processing archive /var/cache/apt/archives/libpng12-0_1.2.54-1ubuntu1.1_amd64.deb (--unpack):
 unable to install new version of '/lib/x86_64-linux-gnu/libpng12.so.0': No such file or directory
No apport report written because the error message indicates an issue on the local system
         Selecting previously unselected package libopenslide0.
Preparing to unpack .../libopenslide0_3.4.0-1build1_amd64.deb ...
Unpacking libopenslide0 (3.4.0-1build1) ...
Selecting previously unselected package openslide-tools.
Preparing to unpack .../openslide-tools_3.4.0-1build1_amd64.deb ...
Unpacking openslide-tools (3.4.0-1build1) ...
Errors were encountered while processing:
 /var/cache/apt/archives/libpng12-0_1.2.54-1ubuntu1.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

安装python-openslide

sudo apt-get install python openslide
报错:

root@node5-SYS-4029GP-TRT:/media/s2/cyq# sudo apt-get install python-openslide
Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 libopenslide0 : Depends: libpng12-0 (>= 1.2.13-4) but it is not going to be installed
 openslide-tools : Depends: libpng12-0 (>= 1.2.13-4) but it is not going to be installed
 python-openslide : Depends: python (< 2.8) but it is not going to be installed
                    Depends: python (>= 2.7~) but it is not going to be installed
                    Depends: python-pil but it is not going to be installed
                    Depends: python:any (>= 2.7.5-5~)
                    Recommends: python-openslide-examples but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

根据指令apt --fix-broken install
报错:

root@node5-SYS-4029GP-TRT:/media/s2/cyq# apt --fix-broken install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  libpng12-0
The following NEW packages will be installed:
  libpng12-0
0 upgraded, 1 newly installed, 0 to remove and 40 not upgraded.
3 not fully installed or removed.
Need to get 0 B/116 kB of archives.
After this operation, 285 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
(Reading database ... 215368 files and directories currently installed.)
Preparing to unpack .../libpng12-0_1.2.54-1ubuntu1.1_amd64.deb ...
Unpacking libpng12-0:amd64 (1.2.54-1ubuntu1.1) ...
dpkg: error processing archive /var/cache/apt/archives/libpng12-0_1.2.54-1ubuntu1.1_amd64.deb (--unpack):
 unable to install new version of '/lib/x86_64-linux-gnu/libpng12.so.0': No such file or directory
No apport report written because the error message indicates an issue on the local system
                                                                                         Errors were encountered while processing:
 /var/cache/apt/archives/libpng12-0_1.2.54-1ubuntu1.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

尝试解决:sudo dpkg -i --force-overwrite /var/cache/apt/archives/libpng12-0_1.2.54-1ubuntu1.1_amd64.deb
报错:

(Reading database ... 215368 files and directories currently installed.)
Preparing to unpack .../libpng12-0_1.2.54-1ubuntu1.1_amd64.deb ...
Unpacking libpng12-0:amd64 (1.2.54-1ubuntu1.1) ...
dpkg: error processing archive /var/cache/apt/archives/libpng12-0_1.2.54-1ubuntu1.1_amd64.deb (--install):
 unable to install new version of '/lib/x86_64-linux-gnu/libpng12.so.0': No such file or directory
Processing triggers for libc-bin (2.29-0ubuntu2) ...
Errors were encountered while processing:
 /var/cache/apt/archives/libpng12-0_1.2.54-1ubuntu1.1_amd64.deb

接着运行:sudo apt-get -f install
报错:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  libpng12-0
The following NEW packages will be installed:
  libpng12-0
0 upgraded, 1 newly installed, 0 to remove and 40 not upgraded.
3 not fully installed or removed.
Need to get 0 B/116 kB of archives.
After this operation, 285 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
(Reading database ... 215368 files and directories currently installed.)
Preparing to unpack .../libpng12-0_1.2.54-1ubuntu1.1_amd64.deb ...
Unpacking libpng12-0:amd64 (1.2.54-1ubuntu1.1) ...
dpkg: error processing archive /var/cache/apt/archives/libpng12-0_1.2.54-1ubuntu1.1_amd64.deb (--unpack):
 unable to install new version of '/lib/x86_64-linux-gnu/libpng12.so.0': No such file or directory
No apport report written because the error message indicates an issue on the local system
         Errors were encountered while processing:
 /var/cache/apt/archives/libpng12-0_1.2.54-1ubuntu1.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

添加适用于ubuntu版本的PPA

sudo add-apt-repository ppa:linuxuprising/libpng12
sudo apt update
sudo apt install libpng12-0
然后openslide-tools顺利安装


安装python-openslide

指令sudo apt-get install python-openslide
报错:

root@node5-SYS-4029GP-TRT:~# sudo apt-get install python-openslide
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 python-openslide : Depends: python (< 2.8) but it is not going to be installed
                    Depends: python (>= 2.7~) but it is not going to be installed
                    Depends: python-pil but it is not going to be installed
                    Depends: python:any (>= 2.7.5-5~)
                    Recommends: python-openslide-examples but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

换成python3-openslide:
sudo apt-get install python3-openslide

root@node5-SYS-4029GP-TRT:~# sudo apt-get install python3-openslide
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 python3-openslide : Depends: python3 (< 3.6) but 3.7.3-1 is to be installed
                     Recommends: python-openslide-examples but it is not going to be installed
E: Unable to correct problems, you have held broken packages.


python降级

重新装一个python3.5版本:
sudo apt-get install python3.5
出现错误:

root@node5-SYS-4029GP-TRT:~# sudo apt-get install python3.5
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 python3.5 : Depends: libpython3.5-stdlib (= 3.5.2-2ubuntu0~16.04.10) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

查找原因:缺少依赖库


安装依赖库

sudo apt-get install libssl1.0.0 libssl-dev tcl tk sqlite sqlite3 libbz2-1.0 libbz2-dev libexpat1 libexpat1-dev libgdbm3 libgdbm-dev  libreadline5 libreadline6 libreadline-dev libreadline6-dev libsqlite0 libsqlite0-dev libsqlite3-0 libsqlite3-dev openssl

出现错误:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
libbz2-1.0 is already the newest version (1.0.6-9ubuntu0.19.04.1).
libbz2-1.0 set to manually installed.
libexpat1 is already the newest version (2.2.6-1ubuntu0.19.5).
libexpat1 set to manually installed.
libsqlite3-0 is already the newest version (3.27.2-2ubuntu0.2).
libsqlite3-0 set to manually installed.
openssl is already the newest version (1.1.1b-1ubuntu2).
openssl set to manually installed.
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libbz2-dev : Depends: libbz2-1.0 (= 1.0.6-8ubuntu0.2) but 1.0.6-9ubuntu0.19.04.1 is to be installed
              Recommends: bzip2-doc but it is not going to be installed
 libexpat1-dev : Depends: libexpat1 (= 2.1.0-7ubuntu0.16.04.5) but 2.2.6-1ubuntu0.19.5 is to be installed
 libreadline5 : Depends: libtinfo5 (>= 6) but it is not going to be installed
 libreadline6 : Depends: libtinfo5 (>= 6) but it is not going to be installed
 libreadline6-dev : Depends: libtinfo-dev but it is not going to be installed
 libsqlite3-dev : Depends: libsqlite3-0 (= 3.11.0-1ubuntu1.4) but 3.27.2-2ubuntu0.2 is to be installed
 libssl-dev : Depends: zlib1g-dev but it is not going to be installed
 sqlite3 : Depends: libsqlite3-0 (= 3.11.0-1ubuntu1.4) but 3.27.2-2ubuntu0.2 is to be installed
E: Unable to correct problems, you have held broken packages.

手动配置依赖库

例如:
sudo apt-get install libbz2-1.0=1.0.6-8ubuntu0.2
然后提示了一个指令,好像是说autoremove什么的,执行了之后,集群就崩了。。。。。。


成功安装的方法

集群重装系统后,按照github的教程2重新安装,直接安装成功,后来发现必须先安装openslide-tools,才能安装python3-openslide(python2就安装python-openslide)
安装步骤:

  1. sudo apt-get install openslide-tools
  2. sudo apt-get install python3-openslide 或者 sudo apt-get install python-openslide(python2)
    此时已经可以了
cyq@NODE5:~$ python
Python 3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 17:14:51) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import openslide
>>> 

如果是还要在conda虚拟环境下使用openslide,则继续进行下一步
3. pip install --no-deps openslide-python

(keras) cyq@NODE5:~$ pip install --no-deps openslide-python
Looking in indexes: http://pypi.tuna.tsinghua.edu.cn/simple/
Processing ./.cache/pip/wheels/a7/d4/0e/a41612c39c92873e6d5ae12cb8be3157b200003defea699dce/openslide_python-1.1.1-cp36-cp36m-linux_x86_64.whl
Installing collected packages: openslide-python
Successfully installed openslide-python-1.1.1
(keras) cyq@NODE5:~$ 
(keras) cyq@NODE5:~$ python
Python 3.6.10 | packaged by conda-forge | (default, Apr  6 2020, 14:52:36) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import openslide
>>> 

完成~~


  1. sudo apt-get update 各种问题!(ubuntu 16.04) ↩︎

  2. python接口的openslide的安装教程 ↩︎

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