当前位置:   article > 正文

Python安装torch模块报错处理_to avoid this problem you can invoke python with '

to avoid this problem you can invoke python with '-m pip' instead of running

前言

因python项目上线,需要在海外服务器上安装指定torch模块

安装

根据官网https://pytorch.org/安装提示,执行pip3 install即可。

pip3 install torch torchvision
  • 1

但安装过程中发生报错,尝试多次执行pip3 install torch torchvision,仍会重置下载。

报错

$ pip3 install torch
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Looking in indexes: http://ap-south-1.mirrors.cloud.aliyuncs.com/pypi/simple/
Collecting torch
  Downloading http://ap-south-1.mirrors.cloud.aliyuncs.com/pypi/packages/62/01/457b49d790b6c4b9720e6f9dbbb617692f6ce8afdaadf425c055c41a7416/torch-1.5.1-cp36-cp36m-manylinux1_x86_64.whl (753.2 MB)
     |████████▊                       | 206.4 MB 48 kB/s eta 3:06:38ERROR: Exception:
Traceback (most recent call last):
  File "/data/python3/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 425, in _error_catcher
    yield
  File "/data/python3/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 507, in read
    data = self._fp.read(amt) if not fp_closed else b""
  File "/data/python3/lib/python3.6/http/client.py", line 449, in read
    n = self.readinto(b)
  File "/data/python3/lib/python3.6/http/client.py", line 493, in readinto
    n = self.fp.readinto(b)
  File "/data/python3/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/data/python3/lib/python3.6/site-packages/pip/_internal/cli/base_command.py", line 188, in _main
    status = self.run(options, args)
  File "/data/python3/lib/python3.6/site-packages/pip/_internal/cli/req_command.py", line 185, in wrapper
    return func(self, options, args)
  File "/data/python3/lib/python3.6/site-packages/pip/_internal/commands/install.py", line 333, in run
    reqs, check_supported_wheels=not options.target_dir
  File "/data/python3/lib/python3.6/site-packages/pip/_internal/resolution/legacy/resolver.py", line 179, in resolve
    discovered_reqs.extend(self._resolve_one(requirement_set, req))
  File "/data/python3/lib/python3.6/site-packages/pip/_internal/resolution/legacy/resolver.py", line 362, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "/data/python3/lib/python3.6/site-packages/pip/_internal/resolution/legacy/resolver.py", line 314, in _get_abstract_dist_for
    abstract_dist = self.preparer.prepare_linked_requirement(req)
  File "/data/python3/lib/python3.6/site-packages/pip/_internal/operations/prepare.py", line 469, in prepare_linked_requirement
    hashes=hashes,
  File "/data/python3/lib/python3.6/site-packages/pip/_internal/operations/prepare.py", line 259, in unpack_url
    hashes=hashes,
  File "/data/python3/lib/python3.6/site-packages/pip/_internal/operations/prepare.py", line 130, in get_http_url
    link, downloader, temp_dir.path, hashes
  File "/data/python3/lib/python3.6/site-packages/pip/_internal/operations/prepare.py", line 281, in _download_http_url
    for chunk in download.chunks:
  File "/data/python3/lib/python3.6/site-packages/pip/_internal/cli/progress_bars.py", line 166, in iter
    for x in it:
  File "/data/python3/lib/python3.6/site-packages/pip/_internal/network/utils.py", line 39, in response_chunks
    decode_content=False,
  File "/data/python3/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 564, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "/data/python3/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 529, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "/data/python3/lib/python3.6/contextlib.py", line 100, in __exit__
    self.gen.throw(type, value, traceback)
  File "/data/python3/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 430, in _error_catcher
    raise ReadTimeoutError(self._pool, None, "Read timed out.")
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host='ap-south-1.mirrors.cloud.aliyuncs.com', port=80): Read timed out.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57

解决

查找文档

https://blog.csdn.net/chr1341901410/article/details/80995451

解决方案

PACKAGE修改成所需要安装的模块

pip install PACKAGE -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
  • 1
安装 torch
pip3 install torch -i http://pypi.douban.com/simple --trusted-host pypi.douban.com   
  • 1
等待安装完成
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Looking in indexes: http://pypi.douban.com/simple
Collecting torch
  Downloading http://pypi.doubanio.com/packages/62/01/457b49d790b6c4b9720e6f9dbbb617692f6ce8afdaadf425c055c41a7416/torch-1.5.1-cp36-cp36m-manylinux1_x86_64.whl (753.2 MB)
     |████████████████████████████████| 753.2 MB 13.3 MB/s 
Requirement already satisfied: numpy in /data/python3/lib/python3.6/site-packages (from torch) (1.19.0)
Collecting future
  Downloading http://pypi.doubanio.com/packages/45/0b/38b06fd9b92dc2b68d58b75f900e97884c45bedd2ff83203d933cf5851c9/future-0.18.2.tar.gz (829 kB)
     |████████████████████████████████| 829 kB 97.0 MB/s 
Using legacy setup.py install for future, since package 'wheel' is not installed.
Installing collected packages: future, torch
    Running setup.py install for future ... done
  WARNING: The scripts convert-caffe2-to-onnx and convert-onnx-to-caffe2 are installed in '/data/python3/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed future-0.18.2 torch-1.5.1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
安装 torchvision
pip3 install torchvision -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
  • 1
提示安装完成
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Looking in indexes: http://pypi.douban.com/simple
Collecting torchvision
  Downloading http://pypi.doubanio.com/packages/9a/f1/535a407b4a265adf2dd7c2c2458217e37c5fe83ec97234e66c564592a9a0/torchvision-0.6.1-cp36-cp36m-manylinux1_x86_64.whl (6.6 MB)
     |████████████████████████████████| 6.6 MB 985 kB/s 
Requirement already satisfied: numpy in /data/python3/lib/python3.6/site-packages (from torchvision) (1.19.0)
Requirement already satisfied: pillow>=4.1.1 in /data/python3/lib/python3.6/site-packages (from torchvision) (7.2.0)
Requirement already satisfied: torch==1.5.1 in /data/python3/lib/python3.6/site-packages (from torchvision) (1.5.1)
Requirement already satisfied: future in /data/python3/lib/python3.6/site-packages (from torch==1.5.1->torchvision) (0.18.2)
Installing collected packages: torchvision
Successfully installed torchvision-0.6.1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

总结

个人认为国内服务器和部分海外服务器安装相关模块不会出现这种情况。可以通过这种方法解决类似问题。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/636026
推荐阅读
相关标签
  

闽ICP备14008679号