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.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章