python3快速安装pytorch

     需要安装pytorch,尝试了几次还是失败。同时,由于pytorch比较大,下载速度也比较慢,在这里总结快速安装pytorch步骤,以拱自己以后参考和同行参考。

一 安装清华镜像

在自己C盘这个路径下(C:\Users\1112\AppData\Roaming),主要是在AppData\Roaming这里,用户(1112)每个电脑可能不同(我的是win10)。然后新建文件夹pip,如下图:

然后在pip文件夹里面新建文本文档pip.ini,里面内容为:

[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn

然后另存为文件pip.ini(格式为所有格式,不是文本类型,这里容易弄错)

成功以后会变为配置文件,在以后用pip安装包时,默认使用清华镜像,速度很快

二 安装pytouch

成功做法:

pip install torch==1.2.0+cpu torchvision==0.4.0+cpu -f https://download.pytorch.org/whl/torch_stable.html

 不到30秒就安装成功(使用镜像的好处)

 

失败提示情况:

C:\Users\1002>pip install pytorch
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pytorch
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x000001903FC29E48>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。')': /simple/pytorch/
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ee/67/f403d4ae6e9cd74b546ee88cccdb29b8415a9c1b3d80aebeb20c9ea91d96/pytorch-1.0.2.tar.gz
Building wheels for collected packages: pytorch
  Building wheel for pytorch (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'E:\software\Anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\1002\\AppData\\Local\\Temp\\pip-install-khgxxu4u\\pytorch\\setup.py'"'"'; __file__='"'"'C:\\Users\\1002\\AppData\\Local\\Temp\\pip-install-khgxxu4u\\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 'C:\Users\1002\AppData\Local\Temp\pip-wheel-pxo1yahy' --python-tag cp37
       cwd: C:\Users\1002\AppData\Local\Temp\pip-install-khgxxu4u\pytorch\
  Complete output (5 lines):
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\1002\AppData\Local\Temp\pip-install-khgxxu4u\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: 'E:\software\Anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\1002\\AppData\\Local\\Temp\\pip-install-khgxxu4u\\pytorch\\setup.py'"'"'; __file__='"'"'C:\\Users\\1002\\AppData\\Local\\Temp\\pip-install-khgxxu4u\\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 'C:\Users\1002\AppData\Local\Temp\pip-record-ml07_20g\install-record.txt' --single-version-externally-managed --compile
         cwd: C:\Users\1002\AppData\Local\Temp\pip-install-khgxxu4u\pytorch\
    Complete output (5 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\1002\AppData\Local\Temp\pip-install-khgxxu4u\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: 'E:\software\Anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\1002\\AppData\\Local\\Temp\\pip-install-khgxxu4u\\pytorch\\setup.py'"'"'; __file__='"'"'C:\\Users\\1002\\AppData\\Local\\Temp\\pip-install-khgxxu4u\\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 'C:\Users\1002\AppData\Local\Temp\pip-record-ml07_20g\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output.

猜你喜欢

转载自blog.csdn.net/qq_39463175/article/details/106897784
今日推荐