此文以anaconda安装各种环境及软件包,用anaconda的好处是:cuda、cunn的安装一步到位,conda会自动搜索适配版本,而不用手动安装。工欲善其事,必先利其器,安装DNN环境前,先把各种镜像(可以理解为应用市场)从默认的国外源换成国内源,这里我选用清华的tuna。
参考清华tuna官网: Anaconda 镜像使用帮助
windows下的.condarc位置:
C/用户/用户名/.condarc
linux下的.condarc位置:
~/.condarc
在default_channels中添加free channel会更全,比如free channel包含python==3.6:
.condarc:
channels:
- defaults
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
# 如果需要使用其他第三方源(参考上方完整列表)
# 例如 conda install -c pytorch-test,则可以添加
#pytorch-test: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
windows下的pip配置文件位置:
C/用户/用户名/pip/pip.ini
没有pip目录就创建一个
linux下的pip配置文件位置:
~/.pip/pip.conf
pip.ini/pip.conf:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = pypi.tuna.tsinghua.edu.cn
创建DNN环境前,需要用conda创建相应python环境
例如要安装tensorflow==1.10.0,先去tensorflow官网查看这个版本的tf对应的python版本:
可以看到最高支持python==3.6,所以:
conda create -n tf_1_10 python==3.6
上式-n表示-name,即要创建的虚拟环境的名称
以安装tensorflow-gpu==1.10.0为例,先进入创建好的虚拟环境:
conda activate tf_1_10
安装tf:
conda install tensorflow-gpu==1.10.0
直接安装 tensorflow-gpu的好处是,不用再安装 tensorflow(CPU),因为tensorflow-gpu已经一步到位安装了tensorflow
tensorflow-gpu验证:
import tensorflow as tf
tf.test.is_gpu_available()
最后一行显示true,即为安装成功
以安装pytorch==1.10.0为例,使用官网命令:
# CUDA 11.3
conda install pytorch==1.10.0 torchvision==0.11.0 torchaudio==0.10.0 cudatoolkit=11.3 -c pytorch -c conda-forge
2022-11-10日更新:
最近一段时间安装python包时,感觉用pip会比conda顺利很多:
pip install package-name