據說pip安pytorch會把自己坑死,您在用的時候具體發現有哪些坑呢?


在官網選好環境就行了,沒什麼坑,就是可能下載慢一點。

(pytorch模型部署以及學習NLP以及模型部署,可以關注一下我的專欄)


不是 pip install pytorch 而是 pip install torch ...

除此之外,貌似沒有遇到過什麼坑,速度慢的話,選擇國內pip源就行了,如清華的pip源就挺快的。


從隔壁conda過來的,還是要推薦一下矩池雲上提供的一鍵換源的腳本。這個收集的是我見過最全的pip國內鏡像源了。

git clone https://github.com/matpool/matools.git
bash /matools/mirrors/switch_apt_source.sh
bash /matools/mirrors/switch_conda_source.sh
bash /matools/mirrors/switch_pip_source.sh

只需要用上面的命令就可以一鍵換源了。

如果在其他地方可以用

阿里云:http://mirrors.aliyun.com/pypi/simple/"
中國科技大學:https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣:https://pypi.doubanio.com/simple/
清華大學:https://pypi.tuna.tsinghua.edu.cn/simple/
騰訊云:https://mirrors.cloud.tencent.com/pypi/simple/
浙江大學:http://mirrors.zju.edu.cn/pypi/web/simple/
網易:http://mirrors.163.com/pypi/simple/
華為云:https://repo.huaweicloud.com/repository/pypi/simple
北京外國語大學:https://mirrors.bfsu.edu.cn/pypi/web/simple
上海交通大學:https://mirrors.sjtug.sjtu.edu.cn/pypi/web/simple
南京大學:https://mirrors.nju.edu.cn/pypi/web/simple

使用辦法如下

臨時使用

pip install -i https://mirrors.bfsu.edu.cn/pypi/web/simple pytorch

設為默認方法1

升級 pip 到最新的版本 (&>=10.0.0) 後進行配置:

pip install pip -U
pip config set global.index-url https://mirrors.bfsu.edu.cn/pypi/web/simple

如果您到 pip 默認源的網路連接較差,臨時使用鏡像源來升級 pip:

pip install -i https://mirrors.bfsu.edu.cn/pypi/web/simple pip -U

設為默認方法2

編輯 pip 配置文件,將 index-url 修改為

https://mirrors.bfsu.edu.cn/pypi/web/simple

pip 的配置文件一般位於(如果沒有,請直接創建):

  • Unix 環境: $HOME/.config/pip/pip.conf
  • macOS: $HOME/Library/Application Support/pip/pip.conf
  • Windows: %APPDATA%pippip.ini

修改pip.conf 文件配置示例如下:

[global]
index-url = https://mirrors.nju.edu.cn/pypi/web/simple
format = columns

希望可以幫助到大家


瀉藥

一般我是添加個清華鏡像源(直接裝我感覺要裝一天

然後pip install + 指定版本

如 pip install pytorch=0.4.1 cuda90

這個就是裝cuda9.0版本的0.4.1版本的pytorch


我覺得我可能懂你

$ pipenv install torch --skip-lock
Installing torch…
Adding torch to Pipfiles [packages]…
Installation Succeeded
Installing dependencies from Pipfile…
An error occurred while installing stanza! Will try again.
An error occurred while installing torch! Will try again.
================================ 4/4 - 00:00:32
Installing initially failed dependencies…
================================ 2/2 - 00:00:12
[pipenv.exceptions.InstallError]: File "c:userspurplappdatalocalprogramspythonpython38libsite-packagespipenvclicommand.py", line 235, in install
[pipenv.exceptions.InstallError]: retcode = do_install(
[pipenv.exceptions.InstallError]: File "c:userspurplappdatalocalprogramspythonpython38libsite-packagespipenvcore.py", line 1983, in do_install
[pipenv.exceptions.InstallError]: do_init(
[pipenv.exceptions.InstallError]: File "c:userspurplappdatalocalprogramspythonpython38libsite-packagespipenvcore.py", line 1246, in do_init
[pipenv.exceptions.InstallError]: do_install_dependencies(
[pipenv.exceptions.InstallError]: File "c:userspurplappdatalocalprogramspythonpython38libsite-packagespipenvcore.py", line 862, in do_install_dependencies
[pipenv.exceptions.InstallError]: _cleanup_procs(procs, False, failed_deps_queue, retry=False)
[pipenv.exceptions.InstallError]: File "c:userspurplappdatalocalprogramspythonpython38libsite-packagespipenvcore.py", line 681, in _cleanup_procs
[pipenv.exceptions.InstallError]: raise exceptions.InstallError(c.dep.name, extra=err_lines)
[pipenv.exceptions.InstallError]: [Looking in indexes: https://mirrors.aliyun.com/pypi/simple/, https://pypi.tuna.tsinghua.edu.cn/simple, Collecting stanza, Using cached https://mirrors.aliyun.com/pypi/packages/27/9c/60689521a971a57dd02d2925105efedefa9dccd76c9a0b92566683d43e89/stanza-1.0.1-py3-none-any.whl (193 kB), Collecting protobuf, Using cached https://mirrors.aliyun.com/pypi/packages/27/9c/ef816295b4b40298fd0a17bf8f0ba6cf3e0c44cb2ce72257168e09996b8b/protobuf-3.11.3-py2.py3-none-any.whl (434 kB)]
[pipenv.exceptions.InstallError]: [ERROR: Could not find a version that satisfies the requirement torch&>=1.3.0 (from stanza) (from versions: 0.1.2, 0.1.2.post1, 0.1.2.post2), ERROR: No matching distribution found for torch&>=1.3.0 (from stanza)]
ERROR: ERROR: Package installation failed...

這是我直接安裝torch的錯誤

後來根據

官網?

pytorch.org

的來

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

emmmmmmmmmmm,終於不報錯了,安裝成功了


conda 清華源


推薦使用conda install pytorch安裝,conda會把pytorch相相應版本的支持包一起下載,掉坑的幾率小一點


安裝可參考 PyTorchversions/網址:

選擇合適版本即可

或者選擇最新版本:PyTorch ,然後選擇複製箭頭命令,如下即可

要是想下載速度快的話,使用清華鏡像,下面命令即可:

pip install torchvision --default-timeout=100 -i https://pypi.tuna.tsinghua.edu.cn/simple


推薦閱讀:
相关文章