在Windows 10上使用pip安装pytorch错误

nvbavucw  于 2023-10-20  发布在  Windows
关注(0)|答案(3)|浏览(170)

我正在尝试使用pip安装pytorch

pip install torch

pip3 install torch===1.3.1 torchvision===0.4.2 -f https://download.pytorch.org/whl/torch_stable.html

Python 3.7.4
Python 3.8(最新稳定版)
32位和64位。
和获得

Collecting torch   Using cached
https://files.pythonhosted.org/packages/f8/02/880b468bd382dc79896eaecbeb8ce95e9c4b99a24902874a2cef0b562cea/torch-0.1.2.post2.tar.gz
Collecting pyyaml (from torch)   Downloading
https://files.pythonhosted.org/packages/bc/3f/4f733cd0b1b675f34beb290d465a65e0f06b492c00b111d1b75125062de1/PyYAML-5.1.2-cp37-cp37m-win_amd64.whl
(215kB)
    100% |████████████████████████████████| 225kB 1.2MB/s Installing collected packages: pyyaml, torch   Running setup.py install for torch
... error
    Complete output from command C:\Noam\Code\threadart\stav-rl\venv\Scripts\python.exe -u -c "import
setuptools,
tokenize;__file__='C:\\Users\\noams\\AppData\\Local\\Temp\\pip-install-djc6s2t8\\torch\\setup.py';f=getattr(tokenize,
'open', open)(__file__);code=f.read( ).replace('\r\n',
'\n');f.close();exec(compile(code, __file__, 'exec'))" install
--record C:\Users\noams\AppData\Local\Temp\pip-record-zohv2zo7\install-record.txt
--single-version-externally-managed --compile --install-headers C:\Noam\Code\threadart\stav-rl\venv\inclu de\site\python3.7\torch:
    running install
    running build_deps
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\noams\AppData\Local\Temp\pip-install-djc6s2t8\torch\setup.py",
line 265, in <module>
        description="Tensors and Dynamic neural networks in Python with strong GPU acceleration",
      File "C:\Noam\Code\threadart\stav-rl\venv\lib\site-packages\setuptools-40.8.0-py3.7.egg\setuptools\__init__.py",
line 145, in setup
      File "C:\Python37_x64\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "C:\Python37_x64\lib\distutils\dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "C:\Python37_x64\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\noams\AppData\Local\Temp\pip-install-djc6s2t8\torch\setup.py",
line 99, in run
        self.run_command('build_deps')
      File "C:\Python37_x64\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "C:\Python37_x64\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\noams\AppData\Local\Temp\pip-install-djc6s2t8\torch\setup.py",
line 51, in run
        from tools.nnwrap import generate_wrappers as generate_nn_wrappers
    ModuleNotFoundError: No module named 'tools.nnwrap'

    ---------------------------------------- Command "C:\Noam\Code\threadart\stav-rl\venv\Scripts\python.exe -u -c "import
setuptools,
tokenize;__file__='C:\\Users\\noams\\AppData\\Local\\Temp\\pip-install-djc6s2t8\\torch\\setup.py';f=getattr(tokenize,
'open', open)(__file__);code=f.read().replace('\r\n', '\n');
f.close();exec(compile(code, __file__, 'exec'))" install --record
C:\Users\noams\AppData\Local\Temp\pip-record-zohv2zo7\install-record.txt
--single-version-externally-managed --compile --install-headers C:\Noam\Code\threadart\stav-rl\venv\include\site\python3.7\torch" 
failed with error code 1 in
C:\Users\noams\AppData\Local\Temp\pip-install-djc6s2t8\torch\

很明显我做错了什么
救命啊!

igsr9ssn

igsr9ssn1#

我也有同样的问题。现在问题解决了。(2020-05-31)
1.访问网站pytorch.org
1.并在pytorch.org的主页上找到“快速入门”。(它可以通过向下滚动一点找到)
1.检查系统的环境形式(例如:Windows,pip,python,)然后,就可以看到install命令了。“pip install torch=....”
1.复制安装命令
1.并在系统中执行命令。
祝你好运!

p1tboqfb

p1tboqfb2#

如果您没有GPU(仅用于CPU),请使用以下命令:

***版本1.2:**conda install pytorch==1.2.0 torchvision==0.4.0 cpuonly -c pytorch
***对于新版本:**conda install pytorch torchvision cpuonly -c pytorch


如果您有GPU,请使用以下命令(使用您自己的CUDA版本):

*版本1.2:conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=10.0 -c pytorch
*新版本:conda install pytorch torchvision cudatoolkit=10.1 -c pytorch

最好使用anaconda命令提示符来安装pytorch,如果可能的话,使用python 3.6。它更合适。Python 3.6对于使用开源库来说更稳定。如果需要,您还可以在下面的链接中找到安装过程,https://medium.com/@bryant.kou/how-to-install-pytorch-on-windows-step-by-step-cc4d004adb2a
如果你只需要用pip来设置这些,你可以试试

对于python 3.6:

pip install https://download.pytorch.org/whl/cpu/torch-1.0.1-cp36-cp36m- win_amd64.whl
pip install torchvision

对于Python 3.7:

pip install https://download.pytorch.org/whl/cpu/torch-1.0.1-cp37-cp37m-win_amd64.whl
pip install torchvision

我认为Conda是更好的选择,而不是在开源库安装pip

lawou6xi

lawou6xi3#

如果您在Windows中使用Anaconda(3.7),则需要通过.whl文件安装。
从此处下载.whl文件:-https://download.pytorch.org/whl/torch_stable.html
然后放入工作目录并使用pip安装,对于我的系统,我将anaconda的pip重命名为pip 37

pip37 install torch-1.5.1+cpu-cp37-cp37m-win_amd64.whl
pip37 install torchvision-0.6.1+cpu-cp37-cp37m-win_amd64.whl

它将在你的anaconda环境中安装Torch1.5和Torchvision 0.6.1

相关问题