1. Anaconda安裝
2. 新建pytorch虛擬環(huán)境
3. 啟動虛擬環(huán)境并安裝pytorch
在官網(wǎng)選擇安裝的版本
https://pytorch.org/get-started/locally/
在Anaconda Prompt中執(zhí)行
添加鏡像源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes
1. 激活pytorch虛擬環(huán)境
activate pytorch
2. 在虛擬環(huán)境中安裝pytorch
conda install pytorch torchvision cpuonly -c pytorch
4. 報錯處理:
安裝過程中報錯:
- CondaHTTPError: HTTP 000 CONNECTION FAILED for url https://conda.anaconda.org/pytorch/win-64/pytorch-1.4.0-py3.7_cpu_0.tar.bz2
- CondaHTTPError: HTTP 000 CONNECTION FAILED for url https://conda.anaconda.org/pytorch/win-64/torchvision-0.5.0-py37_cpu.tar.bz2
- 解決方法:離線下載安裝(將
https://conda.anaconda.org/pytorch/
替換為鏡像源https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
) - 下載報錯的兩個文件到本地并使用
conda install
安裝:
文件1:https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/win-64/pytorch-1.4.0-py3.7_cpu_0.tar.bz2
文件2:https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/torchvision-0.5.0-py37_cpu.tar.bz2
activate pytorch
conda install pytorch-1.4.0-py3.7_cpu_0.tar.bz2
conda install torchvision-0.5.0-py37_cpu.tar.bz2
- 安裝成功
5. VSCode配置pytorch
點擊左下角向叉,切換pytorch
虛擬環(huán)境
6. Jupyter配置pytorch
為Jupyter中添加pytorch kernel
activate pytorch
conda install ipykernel
python -m ipykernel install --user --name pytorch --display-name "Python 3.7(pytorch)"
python -m ipykernel install --user --name 環(huán)境名稱
--display-name "在jupyter中顯示的環(huán)境名稱"
其中pytorch
為annaconda中虛擬環(huán)境名稱, Python 3.7(pytorch)
為該環(huán)境在jupyter中名稱
配置路徑