一、 安装Anaconda
-
Anaconda的安装主要是为了方便环境管理,可以同时在一个电脑上安装多种环境,不同环境放置不同框架:pytorch、tensorflow、keras可以在不同的环境下安装,只需要使用conda create –n创建新环境即可。
-
登录 Anaconda的官网:https://www.anaconda.com/distribution/ 直接下载对应安装包
注意:这里勾选两个(其他按默认勾选即可)
- 配置系统环境
- 下载安装好以后,在cmd查看:
二、 配置torch环境
1、将dos
路径进入到anaconda
安装路径下的Scripts
文件夹下。
-
首先打开
anaconda
安装路径下的Scripts
文件夹。(我的安装在D:\ANACONDA
,所以进入D:\ANACONDA\Scripts
)
2 、创建pytorch环境输入以下命令:
conda create -n pytorch36 python=3.6
创建成功:
3、 激活虚拟环境
activate pytorch36
4、可查看新建环境
三、 安装pytorch
1、所有的操作都要在对应环境中进行,所以在进行库的安装前需要先激活环境。
activate pytorch36
2、添加国内的清华源或者科大源
加快下载速度,激活python36虚拟环境后,输入以下命令,并点击enter即可:
清华源:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
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 --set show_channel_urls yes
科大源:
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
conda config --set show_channel_urls yes
3、官网推荐的安装代码如下,我使用的是Cuda10的版本,对应以下
pip install torch===1.2.0 torchvision===0.4.0 -f https://download.pytorch.org/whl/torch_stable.html
4、其它依赖库的安装
-
先更换源,加快下载速度,在用户文件夹下创建pip文件夹,创建pip记事本
[global] index-url = http://pypi.mirrors.ustc.edu.cn/simple [install] use-mirrors =true mirrors =http://pypi.mirrors.ustc.edu.cn/simple/ trusted-host =pypi.mirrors.ustc.edu.cn
-
保存后将txt 后缀名改为ini 后缀
-
-
在桌面创建记事本保存以下命令,后执行
scipy==1.2.1 numpy==1.17.0 matplotlib==3.1.2 opencv_python==4.1.2.30 torch==1.2.0 torchvision==0.4.0 tqdm==4.60.0 Pillow==8.2.0 h5py==2.10.0
pip install -r C:\Users\86178\Desktop\requirements.txt
- 创建成功