Python安装torch模块报错处理
生活随笔
收集整理的這篇文章主要介紹了
Python安装torch模块报错处理
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Python安裝torch模塊報錯處理
- 前言
- 安裝
- 報錯
- 解決
- 查找文檔
- 解決方案
- 安裝 torch
- 等待安裝完成
- 安裝 torchvision
- 提示安裝完成
- 總結
前言
因python項目上線,需要在海外服務器上安裝指定torch模塊
安裝
根據(jù)官網(wǎng)https://pytorch.org/安裝提示,執(zhí)行pip3 install即可。
pip3 install torch torchvision但安裝過程中發(fā)生報錯,嘗試多次執(zhí)行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 torchDownloading 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_catcheryieldFile "/data/python3/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 507, in readdata = self._fp.read(amt) if not fp_closed else b""File "/data/python3/lib/python3.6/http/client.py", line 449, in readn = self.readinto(b)File "/data/python3/lib/python3.6/http/client.py", line 493, in readinton = self.fp.readinto(b)File "/data/python3/lib/python3.6/socket.py", line 586, in readintoreturn self._sock.recv_into(b) socket.timeout: timed outDuring 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 _mainstatus = self.run(options, args)File "/data/python3/lib/python3.6/site-packages/pip/_internal/cli/req_command.py", line 185, in wrapperreturn func(self, options, args)File "/data/python3/lib/python3.6/site-packages/pip/_internal/commands/install.py", line 333, in runreqs, check_supported_wheels=not options.target_dirFile "/data/python3/lib/python3.6/site-packages/pip/_internal/resolution/legacy/resolver.py", line 179, in resolvediscovered_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_oneabstract_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_forabstract_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_requirementhashes=hashes,File "/data/python3/lib/python3.6/site-packages/pip/_internal/operations/prepare.py", line 259, in unpack_urlhashes=hashes,File "/data/python3/lib/python3.6/site-packages/pip/_internal/operations/prepare.py", line 130, in get_http_urllink, downloader, temp_dir.path, hashesFile "/data/python3/lib/python3.6/site-packages/pip/_internal/operations/prepare.py", line 281, in _download_http_urlfor chunk in download.chunks:File "/data/python3/lib/python3.6/site-packages/pip/_internal/cli/progress_bars.py", line 166, in iterfor x in it:File "/data/python3/lib/python3.6/site-packages/pip/_internal/network/utils.py", line 39, in response_chunksdecode_content=False,File "/data/python3/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 564, in streamdata = self.read(amt=amt, decode_content=decode_content)File "/data/python3/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 529, in readraise 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_catcherraise 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安裝 torch
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 torchDownloading 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 futureDownloading 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, torchRunning setup.py install for future ... doneWARNING: 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安裝 torchvision
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 torchvisionDownloading 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總結
個人認為國內服務器和部分海外服務器安裝相關模塊不會出現(xiàn)這種情況。可以通過這種方法解決類似問題。
總結
以上是生活随笔為你收集整理的Python安装torch模块报错处理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Win10 + WSL2 (ubuntu
- 下一篇: Python+numpy画一幅纯颜色的灰