使用 pip 安装 PyTorch 时出错 - 无法构建轮子

loo*_*ick -2 python linux pip python-3.x pytorch

当我尝试运行pip3 install pytorchpip install pytorch

Collecting pytorch
  Using cached pytorch-1.0.2.tar.gz (689 bytes)
Building wheels for collected packages: pytorch
  Building wheel for pytorch (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/chaitanya/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-3v4wd97t/pytorch/setup.py'"'"'; __file__='"'"'/tmp/pip-install-3v4wd97t/pytorch/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-8rsdyb8e
       cwd: /tmp/pip-install-3v4wd97t/pytorch/
  Complete output (5 lines):
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-install-3v4wd97t/pytorch/setup.py", line 15, in <module>
      raise Exception(message)
  Exception: You tried to install "pytorch". The package named for PyTorch is "torch"
  ----------------------------------------
  ERROR: Failed building wheel for pytorch
  Running setup.py clean for pytorch
Failed to build pytorch
Installing collected packages: pytorch
    Running setup.py install for pytorch ... error
    ERROR: Command errored out with exit status 1:
     command: /home/chaitanya/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-3v4wd97t/pytorch/setup.py'"'"'; __file__='"'"'/tmp/pip-install-3v4wd97t/pytorch/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-eld9j0g4/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/chaitanya/.local/include/python3.8/pytorch
         cwd: /tmp/pip-install-3v4wd97t/pytorch/
    Complete output (5 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-3v4wd97t/pytorch/setup.py", line 11, in <module>
        raise Exception(message)
    Exception: You tried to install "pytorch". The package named for PyTorch is "torch"
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/chaitanya/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-3v4wd97t/pytorch/setup.py'"'"'; __file__='"'"'/tmp/pip-install-3v4wd97t/pytorch/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-eld9j0g4/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/chaitanya/.local/include/python3.8/pytorch Check the logs for full command output.
Run Code Online (Sandbox Code Playgroud)

我从这里下载了匹配的轮子,但我不知道如何处理它。如果需要,我的 Python 安装正在使用 anaconda3。我应该从这里做什么?关于我如何自己解决这个问题的提示也将不胜感激。

Fly*_*ler 6

从你的错误:

Exception: You tried to install "pytorch". The package named for PyTorch is "torch"

它告诉你你需要知道什么,而不是

pip install pytorch
Run Code Online (Sandbox Code Playgroud)

它应该是

pip install torch
Run Code Online (Sandbox Code Playgroud)

我从这里下载了匹配的轮子,但我不知道如何处理它

安装.whl文件很简单

pip install <path to .whl file>
Run Code Online (Sandbox Code Playgroud)

我的 Python 安装使用的是 anaconda3

这是非常相关的。您通常应该尽可能避免pip在您的 conda 环境中使用。相反,您可以conda installpytroch.org为您的设置(cuda 版本等)找到正确的命令,例如对于 cuda 11,它将是

conda install pytorch torchvision torchaudio cudatoolkit=11.0 -c pytorch
Run Code Online (Sandbox Code Playgroud)