Pycharm 中Torch安装方法
1.使用自带工具安装
依次打开菜单:File->Setting
点击+号,搜索torch
选择1.13.0版本安装
安装错误:
具体包含很长一段错误记录,如下:
Collecting torch==1.13.0 Downloading https://files.pythonhosted.org/packages/ec/5e/88854e28b3cb1cd5439d13299bde21b85be810d8d43f3547d72094e05eba/torch-1.13.0-cp37-cp37m-win_amd64.whl (167.3MB)ERROR: Exception:Traceback (most recent call last): File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 397, in _error_catcher yield File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 479, in read data = self._fp.read(amt) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 62, in read data = self.__fp.read(amt) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 457, in read n = self.readinto(b) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 501, in readinto n = self.fp.readinto(b) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\socket.py", line 589, in readinto return self._sock.recv_into(b) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1071, in recv_into return self.read(nbytes, buffer) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 929, in read return self._sslobj.read(len, buffer)socket.timeout: The read operation timed outDuring handling of the above exception, another exception occurred:Traceback (most recent call last): File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\cli\base_command.py", line 188, in main status = self.run(options, args) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\commands\install.py", line 345, in run resolver.resolve(requirement_set) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\legacy_resolve.py", line 196, in resolve self._resolve_one(requirement_set, req) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\legacy_resolve.py", line 359, in _resolve_one abstract_dist = self._get_abstract_dist_for(req_to_install) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\legacy_resolve.py", line 307, in _get_abstract_dist_for self.require_hashes File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\operations\prepare.py", line 199, in prepare_linked_requirement progress_bar=self.progress_bar File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\download.py", line 1064, in unpack_url progress_bar=progress_bar File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\download.py", line 924, in unpack_http_url progress_bar) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\download.py", line 1152, in _download_http_url _download_url(resp, link, content_file, hashes, progress_bar) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\download.py", line 861, in _download_url hashes.check_against_chunks(downloaded_chunks) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\utils\hashes.py", line 75, in check_against_chunks for chunk in chunks: File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\download.py", line 829, in written_chunks for chunk in chunks: File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\utils\ui.py", line 156, in iter for x in it: File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\download.py", line 818, in resp_read decode_content=False): File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 531, in stream data = self.read(amt=amt, decode_content=decode_content) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 496, in read raise IncompleteRead(self._fp_bytes_read, self.length_remaining) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\contextlib.py", line 130, in __exit__ self.gen.throw(type, value, traceback) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 402, 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.WARNING: You are using pip version 19.2.3, however version 23.0 is available.You should consider upgrading via the 'python -m pip install --upgrade pip' command.
2.使用pip命令安装
从上面我们可以看到whl文件的下载地址以及文件大小,具体为:
我们按照这个地址将文件下载下来,然后使用pip命令安装。
其他版本Torch和Torchvision地址:https://download.pytorch.org/whl/torch_stable.html
(1)将torch-1.13.0-cp37-cp37m-win_amd64.whl 文件复制到编译器路径下
具体地址为:C:\Users\Administrator\AppData\Local\Programs\Python\Python37\Scripts
定位到pycharm中使用的编译器地址:
这是默认的地址,如果是新设置项目的地址就选择对应的新地址。
(2)'win+r' 输入cmd
输入:cd C:\Users\Administrator\AppData\Local\Programs\Python\Python37\Scripts
指定安装路径
输入命令:pip install torch-1.13.0-cp37-cp37m-win_amd64.whl
安装成功以后:
3.运行测试
安装好之后,缺失的包提示波浪线不显示,表示安装成功了。
‘import torch_optimizer as optim’改为‘import torch.optim as optim’
from torchsummary import summary中的torchsummary单独安装
补充:torch和torchvision版本对应关系:以win py37m 为例
torch1.12.0--torchvision-0.13.0
torch1.12.1--torchvision-0.13.1
torch1.13.0--torchvision-0.14.0
torch1.13.1--torchvision-0.14.1
来源地址:https://blog.csdn.net/soderayer/article/details/128881688
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341