项目场景:
提示:这里简述项目相关背景:
例如:项目需求安装pytorch,安装神经网络环境配置。
问题描述
提示:这里描述项目中遇到的问题:
安装pytorch
官网 https://pytorch.org/ 详细看官方提供的手册
安装时选择cuda11.8的版本(与电脑安装的驱动版本一致,需要提前安装好驱动)
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
C:\Users\14397>pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
Looking in indexes: https://download.pytorch.org/whl/cu118
Requirement already satisfied: torch in c:\users\14397\appdata\roaming\python\python312\site-packages (2.2.0)
Requirement already satisfied: torchvision in c:\users\14397\appdata\roaming\python\python312\site-packages (0.17.0)
Collecting torchaudioUsing cached https://download.pytorch.org/whl/cu118/torchaudio-2.2.0%2Bcu118-cp312-cp312-win_amd64.whl (3.9 MB)
Requirement already satisfied: filelock in c:\users\14397\appdata\roaming\python\python312\site-packages (from torch) (3.13.1)
Requirement already satisfied: typing-extensions>=4.8.0 in c:\python312\lib\site-packages (from torch) (4.9.0)
Requirement already satisfied: sympy in c:\python312\lib\site-packages (from torch) (1.12)
Requirement already satisfied: networkx in c:\users\14397\appdata\roaming\python\python312\site-packages (from torch) (3.2.1)
Requirement already satisfied: jinja2 in c:\users\14397\appdata\roaming\python\python312\site-packages (from torch) (3.1.3)
Requirement already satisfied: fsspec in c:\users\14397\appdata\roaming\python\python312\site-packages (from torch) (2024.2.0)
Requirement already satisfied: numpy in c:\python312\lib\site-packages (from torchvision) (1.26.4)
Requirement already satisfied: requests in c:\users\14397\appdata\roaming\python\python312\site-packages (from torchvision) (2.31.0)
Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in c:\python312\lib\site-packages (from torchvision) (10.2.0)
Collecting torchDownloading https://download.pytorch.org/whl/cu118/torch-2.2.0%2Bcu118-cp312-cp312-win_amd64.whl (2704.2 MB)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸━━━ 2.5/2.7 GB 1.6 MB/s eta 0:02:18
ERROR: Exception:
Traceback (most recent call last):File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_vendor\urllib3\response.py", line 438, in _error_catcheryieldFile "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_vendor\urllib3\response.py", line 561, in readdata = self._fp_read(amt) if not fp_closed else b""^^^^^^^^^^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_vendor\urllib3\response.py", line 527, in _fp_readreturn self._fp.read(amt) if amt is not None else self._fp.read()^^^^^^^^^^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 98, in readdata: bytes = self.__fp.read(amt)^^^^^^^^^^^^^^^^^^^File "C:\Python312\Lib\http\client.py", line 472, in reads = self.fp.read(amt)^^^^^^^^^^^^^^^^^File "C:\Python312\Lib\socket.py", line 707, in readintoreturn self._sock.recv_into(b)^^^^^^^^^^^^^^^^^^^^^^^File "C:\Python312\Lib\ssl.py", line 1249, in recv_intoreturn self.read(nbytes, buffer)^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Python312\Lib\ssl.py", line 1105, in readreturn self._sslobj.read(len, buffer)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TimeoutError: The read operation timed outDuring handling of the above exception, another exception occurred:Traceback (most recent call last):File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_internal\cli\base_command.py", line 180, in exc_logging_wrapperstatus = run_func(*args)^^^^^^^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_internal\cli\req_command.py", line 245, in wrapperreturn func(self, options, args)^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_internal\commands\install.py", line 377, in runrequirement_set = resolver.resolve(^^^^^^^^^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 95, in resolveresult = self._result = resolver.resolve(^^^^^^^^^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_vendor\resolvelib\resolvers.py", line 546, in resolvestate = resolution.resolve(requirements, max_rounds=max_rounds)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_vendor\resolvelib\resolvers.py", line 427, in resolvefailure_causes = self._attempt_to_pin_criterion(name)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_vendor\resolvelib\resolvers.py", line 239, in _attempt_to_pin_criterioncriteria = self._get_updated_criteria(candidate)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_vendor\resolvelib\resolvers.py", line 230, in _get_updated_criteriaself._add_to_criteria(criteria, requirement, parent=candidate)File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_vendor\resolvelib\resolvers.py", line 173, in _add_to_criteriaif not criterion.candidates:^^^^^^^^^^^^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_vendor\resolvelib\structs.py", line 156, in __bool__return bool(self._sequence)^^^^^^^^^^^^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 155, in __bool__return any(self)^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 143, in <genexpr>return (c for c in iterator if id(c) not in self._incompatible_ids)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 47, in _iter_builtcandidate = func()^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 182, in _make_candidate_from_linkbase: Optional[BaseCandidate] = self._make_base_candidate_from_link(^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 228, in _make_base_candidate_from_linkself._link_candidate_cache[link] = LinkCandidate(^^^^^^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 290, in __init__super().__init__(File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 156, in __init__self.dist = self._prepare()^^^^^^^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 222, in _preparedist = self._prepare_distribution()^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 301, in _prepare_distributionreturn preparer.prepare_linked_requirement(self._ireq, parallel_builds=True)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_internal\operations\prepare.py", line 525, in prepare_linked_requirementreturn self._prepare_linked_requirement(req, parallel_builds)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_internal\operations\prepare.py", line 596, in _prepare_linked_requirementlocal_file = unpack_url(^^^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_internal\operations\prepare.py", line 168, in unpack_urlfile = get_http_url(^^^^^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_internal\operations\prepare.py", line 109, in get_http_urlfrom_path, content_type = download(link, temp_dir.path)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_internal\network\download.py", line 147, in __call__for chunk in chunks:File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_internal\cli\progress_bars.py", line 53, in _rich_progress_barfor chunk in iterable:File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_internal\network\utils.py", line 63, in response_chunksfor chunk in response.raw.stream(File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_vendor\urllib3\response.py", line 622, in streamdata = self.read(amt=amt, decode_content=decode_content)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_vendor\urllib3\response.py", line 560, in readwith self._error_catcher():File "C:\Python312\Lib\contextlib.py", line 155, in __exit__self.gen.throw(value)File "C:\Users\14397\AppData\Roaming\Python\Python312\site-packages\pip\_vendor\urllib3\response.py", line 443, in _error_catcherraise ReadTimeoutError(self._pool, None, "Read timed out.")
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='download.pytorch.org', port=443): Read timed out.
指令:
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
该命令是用来通过pip3(Python的包管理工具)安装PyTorch及其相关库torchvision和torchaudio的。具体来说,这个命令的作用如下:
pip3 install
: 使用pip3来安装Python包。pip3是Python 3的包管理工具,用于从Python Package Index(PyPI)或其他源安装Python包。torch
: PyTorch是一个开源的深度学习库,广泛用于各种机器学习和深度学习应用。torchvision
: torchvision是PyTorch的一个扩展库,提供了计算机视觉中常用的数据集、模型、图像转换等功能。torchaudio
: torchaudio是另一个PyTorch的扩展库,专门用于音频处理。--index-url https://download.pytorch.org/whl/cu118
: 这个参数指定了pip3从哪个URL下载这些包。这里,它指定了一个特定的URL,该URL包含了为CUDA 11.8版本编译的PyTorch包。这意味着如果你的机器上安装了NVIDIA的CUDA 11.8版本,并且你有一块支持CUDA的NVIDIA显卡,那么这个命令将下载并安装与CUDA 11.8兼容的PyTorch版本。
总之,这个命令用于安装与CUDA 11.8兼容的PyTorch、torchvision和torchaudio库。这通常用于加速深度学习模型的训练和推理,特别是在具有NVIDIA GPU的计算机上。
原因分析:
提示:这里填写问题的分析:
网络问题:
继续装
C:\Users\14397>pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
Looking in indexes: https://download.pytorch.org/whl/cu118
Requirement already satisfied: torch in c:\users\14397\appdata\roaming\python\python312\site-packages (2.2.0)
Requirement already satisfied: torchvision in c:\users\14397\appdata\roaming\python\python312\site-packages (0.17.0)
Collecting torchaudioUsing cached https://download.pytorch.org/whl/cu118/torchaudio-2.2.0%2Bcu118-cp312-cp312-win_amd64.whl (3.9 MB)
Requirement already satisfied: filelock in c:\users\14397\appdata\roaming\python\python312\site-packages (from torch) (3.13.1)
Requirement already satisfied: typing-extensions>=4.8.0 in c:\python312\lib\site-packages (from torch) (4.9.0)
Requirement already satisfied: sympy in c:\python312\lib\site-packages (from torch) (1.12)
Requirement already satisfied: networkx in c:\users\14397\appdata\roaming\python\python312\site-packages (from torch) (3.2.1)
Requirement already satisfied: jinja2 in c:\users\14397\appdata\roaming\python\python312\site-packages (from torch) (3.1.3)
Requirement already satisfied: fsspec in c:\users\14397\appdata\roaming\python\python312\site-packages (from torch) (2024.2.0)
Requirement already satisfied: numpy in c:\python312\lib\site-packages (from torchvision) (1.26.4)
Requirement already satisfied: requests in c:\users\14397\appdata\roaming\python\python312\site-packages (from torchvision) (2.31.0)
Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in c:\python312\lib\site-packages (from torchvision) (10.2.0)
Collecting torchDownloading https://download.pytorch.org/whl/cu118/torch-2.2.0%2Bcu118-cp312-cp312-win_amd64.whl (2704.2 MB)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.7/2.7 GB 1.5 MB/s eta 0:00:00
Requirement already satisfied: MarkupSafe>=2.0 in c:\users\14397\appdata\roaming\python\python312\site-packages (from jinja2->torch) (2.1.5)
Requirement already satisfied: charset-normalizer<4,>=2 in c:\users\14397\appdata\roaming\python\python312\site-packages (from requests->torchvision) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in c:\users\14397\appdata\roaming\python\python312\site-packages (from requests->torchvision) (3.6)
Requirement already satisfied: urllib3<3,>=1.21.1 in c:\python312\lib\site-packages (from requests->torchvision) (2.2.0)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\14397\appdata\roaming\python\python312\site-packages (from requests->torchvision) (2024.2.2)
Requirement already satisfied: mpmath>=0.19 in c:\python312\lib\site-packages (from sympy->torch) (1.3.0)
Installing collected packages: torch, torchaudioAttempting uninstall: torchFound existing installation: torch 2.2.0Uninstalling torch-2.2.0:Successfully uninstalled torch-2.2.0
安装成功。
解决方案:
网络问题,继续装看运气。