首先,之所以会出现ModuleNotFoundError
这一系列的报错信息,是由于缺少指定的库文件。正如标题中所涉及到的这个错误,正是由于缺少skimage(Scikit-Image,一个处理数字图像的库文件) 库,本文将介绍如何安装该库文件,同时会提到如何使用国内的镜像来快速下载库文件。
首先,我们先来看看报错信息吧:
[**@** EfficientNet]# python training.py
Using TensorFlow backend.
Traceback (most recent call last):
File "training.py", line 17, in
from efficientnet import EfficientNetB0 as Net # Import efficientnet and load the conv base model
File "/**/EfficientNet/efficientnet/__init__.py", line 2, in
from .preprocessing import center_crop_and_resize
File "/**/EfficientNet/efficientnet/preprocessing.py", line 2, in
from skimage.transform import resize
ModuleNotFoundError: No module named 'skimage'
既然是因为缺少skimage文件所引起的报错,那么我们就通过pip install scikit-image
命令来安装它,可是在安装的时候可能会发现:
[**@** EfficientNet]# pip install scikit-image
Collecting scikit-image
Downloading https://files.pythonhosted.org/packages/c8/bb/771800366f41d66eef51e4b80515f8ef7edab234a3f244fdce3bafe89b39/scikit_image-0.16.2-cp36-cp36m-manylinux1_x86_64.whl (26.5MB)
0% |▎ | 235kB 6.8kB/s eta 1:04:13Exception:
Traceback (most recent call last):
File "/usr/local/python3/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 360, in _error_catcher
yield
File "/usr/local/python3/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 442, in read
data = self._fp.read(amt)
File "/usr/local/python3/lib/python3.6/site-packages/pip/_vendor/cachecontrol/filewrapper.py", line 62, in read
data = self.__fp.read(amt)
File "/usr/local/python3/lib/python3.6/http/client.py", line 449, in read
n = self.readinto(b)
File "/usr/local/python3/lib/python3.6/http/client.py", line 493, in readinto
n = self.fp.readinto(b)
File "/usr/local/python3/lib/python3.6/socket.py", line 586, in readinto
return self._sock.recv_into(b)
File "/usr/local/python3/lib/python3.6/ssl.py", line 1012, in recv_into
return self.read(nbytes, buffer)
File "/usr/local/python3/lib/python3.6/ssl.py", line 874, in read
return self._sslobj.read(len, buffer)
File "/usr/local/python3/lib/python3.6/ssl.py", line 631, in read
v = self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/python3/lib/python3.6/site-packages/pip/_internal/cli/base_command.py", line 179, in main
status = self.run(options, args)
File "/usr/local/python3/lib/python3.6/site-packages/pip/_internal/commands/install.py", line 315, in run
resolver.resolve(requirement_set)
File "/usr/local/python3/lib/python3.6/site-packages/pip/_internal/resolve.py", line 131, in resolve
self._resolve_one(requirement_set, req)
File "/usr/local/python3/lib/python3.6/site-packages/pip/_internal/resolve.py", line 294, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "/usr/local/python3/lib/python3.6/site-packages/pip/_internal/resolve.py", line 242, in _get_abstract_dist_for
self.require_hashes
File "/usr/local/python3/lib/python3.6/site-packages/pip/_internal/operations/prepare.py", line 334, in prepare_linked_requirement
progress_bar=self.progress_bar
File "/usr/local/python3/lib/python3.6/site-packages/pip/_internal/download.py", line 878, in unpack_url
progress_bar=progress_bar
File "/usr/local/python3/lib/python3.6/site-packages/pip/_internal/download.py", line 702, in unpack_http_url
progress_bar)
File "/usr/local/python3/lib/python3.6/site-packages/pip/_internal/download.py", line 946, in _download_http_url
_download_url(resp, link, content_file, hashes, progress_bar)
File "/usr/local/python3/lib/python3.6/site-packages/pip/_internal/download.py", line 639, in _download_url
hashes.check_against_chunks(downloaded_chunks)
File "/usr/local/python3/lib/python3.6/site-packages/pip/_internal/utils/hashes.py", line 62, in check_against_chunks
for chunk in chunks:
File "/usr/local/python3/lib/python3.6/site-packages/pip/_internal/download.py", line 607, in written_chunks
for chunk in chunks:
File "/usr/local/python3/lib/python3.6/site-packages/pip/_internal/utils/ui.py", line 159, in iter
for x in it:
File "/usr/local/python3/lib/python3.6/site-packages/pip/_internal/download.py", line 596, in resp_read
decode_content=False):
File "/usr/local/python3/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 494, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/usr/local/python3/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 459, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "/usr/local/python3/lib/python3.6/contextlib.py", line 99, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/local/python3/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 365, in _error_catcher
raise ReadTimeoutError(self._pool, None, 'Read timed out.')
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
You are using pip version 19.0.3, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
可以看到,使用刚才的命令安装skimage库时候,报出了ReadTimeoutError
的错误,直接从指定的网址下载的时候,由于网络的原因,出现这种情况很正常,此时的我们灵机一动,想到可以选择使用国内的镜像来下载安装该文件,这样的话下载安装的速度就和刚才的不可同日而语了。
首先列举国内的一些镜像(排名不分先后):
镜像源 | 网址 |
---|---|
清华大学 | https://pypi.tuna.tsinghua.edu.cn/simple/ |
中国科学技术大学 | http://pypi.mirrors.ustc.edu.cn/simple/ |
中国科技大学 | https://pypi.mirrors.ustc.edu.cn/simple/ |
阿里云 | http://mirrors.aliyun.com/pypi/simple/ |
豆瓣(douban) | http://pypi.douban.com/simple/ |
使用国内镜像下载库文件的时候,可以在pip
后面加上要安装的库文件名称,接着跟上参数-i
,最后加上要指定下载的镜像源网址即可,如果有提示要安装的文件有风险,那么我们可以在最后加上一个--trusted-host
命令[1]。
举个栗子,如果是要选择使用豆瓣镜像的话,就要输入pip install scikit-image -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
命令,安装过程如下:
[**@** EfficientNet]# pip install scikit-image -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
Looking in indexes: http://pypi.douban.com/simple/
Collecting scikit-image
Downloading http://pypi.doubanio.com/packages/c8/bb/771800366f41d66eef51e4b80515f8ef7edab234a3f244fdce3bafe89b39/scikit_image-0.16.2-cp36-cp36m-manylinux1_x86_64.whl (26.5MB)
100% |████████████████████████████████| 26.5MB 1.1MB/s
Requirement already satisfied: matplotlib!=3.0.0,>=2.0.0 in /usr/local/python3/lib/python3.6/site-packages (from scikit-image) (3.0.3)
Collecting imageio>=2.3.0 (from scikit-image)
Downloading http://pypi.doubanio.com/packages/1a/de/f7f985018f462ceeffada7f6e609919fbcc934acd9301929cba14bc2c24a/imageio-2.6.1-py3-none-any.whl (3.3MB)
100% |████████████████████████████████| 3.3MB 821kB/s
Collecting PyWavelets>=0.4.0 (from scikit-image)
Downloading http://pypi.doubanio.com/packages/59/bb/d2b85265ec9fa3c1922210c9393d4cdf7075cc87cce6fe671d7455f80fbc/PyWavelets-1.1.1-cp36-cp36m-manylinux1_x86_64.whl (4.4MB)
100% |████████████████████████████████| 4.4MB 1.9MB/s
Collecting networkx>=2.0 (from scikit-image)
Downloading http://pypi.doubanio.com/packages/41/8f/dd6a8e85946def36e4f2c69c84219af0fa5e832b018c970e92f2ad337e45/networkx-2.4-py3-none-any.whl (1.6MB)
100% |████████████████████████████████| 1.6MB 829kB/s
Requirement already satisfied: scipy>=0.19.0 in /usr/local/python3/lib/python3.6/site-packages (from scikit-image) (1.2.1)
Requirement already satisfied: pillow>=4.3.0 in /usr/local/python3/lib/python3.6/site-packages (from scikit-image) (6.0.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/python3/lib/python3.6/site-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image) (1.0.1)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/python3/lib/python3.6/site-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image) (2.4.0)
Requirement already satisfied: numpy>=1.10.0 in /usr/local/python3/lib/python3.6/site-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image) (1.16.2)
Requirement already satisfied: cycler>=0.10 in /usr/local/python3/lib/python3.6/site-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image) (0.10.0)
Requirement already satisfied: python-dateutil>=2.1 in /usr/local/python3/lib/python3.6/site-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image) (2.8.0)
Requirement already satisfied: decorator>=4.3.0 in /usr/local/python3/lib/python3.6/site-packages (from networkx>=2.0->scikit-image) (4.4.0)
Requirement already satisfied: setuptools in /usr/local/python3/lib/python3.6/site-packages (from kiwisolver>=1.0.1->matplotlib!=3.0.0,>=2.0.0->scikit-image) (40.8.0)
Requirement already satisfied: six in /usr/local/python3/lib/python3.6/site-packages (from cycler>=0.10->matplotlib!=3.0.0,>=2.0.0->scikit-image) (1.12.0)
Installing collected packages: imageio, PyWavelets, networkx, scikit-image
Successfully installed PyWavelets-1.1.1 imageio-2.6.1 networkx-2.4 scikit-image-0.16.2
You are using pip version 19.0.3, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
可以看到在使用国内的镜像源之后,安装速度已经是飞快了,并没有报出ReadTimeoutError
等错误。
————————————2020.04.15补充————————————
同样的道理,如果要安装其他库文件的时候,同样可以使用上述命令语句进行,比如要安装torch==1.0.1
的库文件,那么就可以照猫画虎,输入以下语句pip install torch==1.0.1 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
进行安装,安装过程如下:
[**@** ]# pip install torch==1.0.1 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
Looking in indexes: http://pypi.douban.com/simple/
Collecting torch==1.0.1
Downloading http://pypi.doubanio.com/packages/f7/92/1ae072a56665e36e81046d5fb8a2f39c7728c25c21df1777486c49b179ae/torch-1.0.1-cp36-cp36m-manylinux1_x86_64.whl (560.0MB)
100% |████████████████████████████████| 560.1MB 12.4MB/s
Installing collected packages: torch
Successfully installed torch-1.0.1
You are using pip version 19.0.3, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
至此,torch==1.0.1
库安装完成。
写到这里,差不多本文就要结束了,如有问题欢迎在下方留言区留言交流。如果我的这篇文章帮助到了你,那我也会感到很高兴,一个人能走多远,在于与谁同行。
[1] PyPI使用国内源