当前位置:   article > 正文

Pycharm 中Torch安装方法_pycharm安装torch

pycharm安装torch

1.使用自带工具安装

依次打开菜单:File->Setting

点击+号,搜索torch

选择1.13.0版本安装

安装错误:

具体包含很长一段错误记录,如下:

  1. Collecting torch==1.13.0
  2. Downloading https://files.pythonhosted.org/packages/ec/5e/88854e28b3cb1cd5439d13299bde21b85be810d8d43f3547d72094e05eba/torch-1.13.0-cp37-cp37m-win_amd64.whl (167.3MB)
  3. ERROR: Exception:
  4. Traceback (most recent call last):
  5. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 397, in _error_catcher
  6. yield
  7. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 479, in read
  8. data = self._fp.read(amt)
  9. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 62, in read
  10. data = self.__fp.read(amt)
  11. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 457, in read
  12. n = self.readinto(b)
  13. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 501, in readinto
  14. n = self.fp.readinto(b)
  15. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\socket.py", line 589, in readinto
  16. return self._sock.recv_into(b)
  17. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1071, in recv_into
  18. return self.read(nbytes, buffer)
  19. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 929, in read
  20. return self._sslobj.read(len, buffer)
  21. socket.timeout: The read operation timed out
  22. During handling of the above exception, another exception occurred:
  23. Traceback (most recent call last):
  24. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\cli\base_command.py", line 188, in main
  25. status = self.run(options, args)
  26. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\commands\install.py", line 345, in run
  27. resolver.resolve(requirement_set)
  28. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\legacy_resolve.py", line 196, in resolve
  29. self._resolve_one(requirement_set, req)
  30. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\legacy_resolve.py", line 359, in _resolve_one
  31. abstract_dist = self._get_abstract_dist_for(req_to_install)
  32. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\legacy_resolve.py", line 307, in _get_abstract_dist_for
  33. self.require_hashes
  34. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\operations\prepare.py", line 199, in prepare_linked_requirement
  35. progress_bar=self.progress_bar
  36. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\download.py", line 1064, in unpack_url
  37. progress_bar=progress_bar
  38. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\download.py", line 924, in unpack_http_url
  39. progress_bar)
  40. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\download.py", line 1152, in _download_http_url
  41. _download_url(resp, link, content_file, hashes, progress_bar)
  42. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\download.py", line 861, in _download_url
  43. hashes.check_against_chunks(downloaded_chunks)
  44. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\utils\hashes.py", line 75, in check_against_chunks
  45. for chunk in chunks:
  46. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\download.py", line 829, in written_chunks
  47. for chunk in chunks:
  48. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\utils\ui.py", line 156, in iter
  49. for x in it:
  50. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\download.py", line 818, in resp_read
  51. decode_content=False):
  52. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 531, in stream
  53. data = self.read(amt=amt, decode_content=decode_content)
  54. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 496, in read
  55. raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  56. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\contextlib.py", line 130, in __exit__
  57. self.gen.throw(type, value, traceback)
  58. File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 402, in _error_catcher
  59. raise ReadTimeoutError(self._pool, None, 'Read timed out.')
  60. pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
  61. WARNING: You are using pip version 19.2.3, however version 23.0 is available.
  62. 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

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

闽ICP备14008679号