赞
踩
因python项目上线,需要在海外服务器上安装指定torch模块
根据官网https://pytorch.org/安装提示,执行pip3 install即可。
pip3 install torch torchvision
但安装过程中发生报错,尝试多次执行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.
https://blog.csdn.net/chr1341901410/article/details/80995451
PACKAGE修改成所需要安装的模块
pip install PACKAGE -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
pip3 install torch -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
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
pip3 install torchvision -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
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
个人认为国内服务器和部分海外服务器安装相关模块不会出现这种情况。可以通过这种方法解决类似问题。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。