返回顶部
首页 > 资讯 > 后端开发 > Python >Pycharm 中Torch安装方法
  • 453
分享到

Pycharm 中Torch安装方法

pycharmpythonPoweredby金山文档 2023-09-09 14:09:55 453人浏览 八月长安

Python 官方文档:入门教程 => 点击学习

摘要

1.使用自带工具安装 依次打开菜单:File->Setting 点击+号,搜索torch 选择1.13.0版本安装 安装错误: 具体包含很

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文件的下载地址以及文件大小,具体为:

https://files.pythonhosted.org/packages/ec/5e/88854e28b3cb1cd5439d13299bde21b85be810d8d43f3547d72094e05eba/torch-1.13.0-cp37-cp37m-win_amd64.whl (167.3MB)

我们按照这个地址将文件下载下来,然后使用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

--结束END--

本文标题: Pycharm 中Torch安装方法

本文链接: https://lsjlt.com/news/401629.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作