使用Miniconda一行代码配置Pytorch环境


安装显卡驱动

下载最新版的nvidia驱动安装即可。

安装miniconda

安装anaconda同理,只需要下载对应的anaconda即可。我主要是不需要anaconda自带的科学计算包,所以就选择了miniconda

  1. 在清华镜像站中,下载miniconda

    # 清华镜像站地址
    https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/
    
  2. 安装miniconda,首先进入到安装文件所在文件夹

    bash Miniconda3-latest-Linux-x86_64.sh
    

    在安装的过程中,会问是否同意许可,输入yes,之后会让你选择安装在哪,如无特殊要求,直接回车,安装在默认位置即可。

设置镜像源

  • 通过在修改在用户目录下的.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/free
      - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
    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
      simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
    
  • 如果不存在该文件,可以直接创建一个,再修改即可

    touch .condarc
    

安装具体的深度学习环境

安装tensorflow

  • tensorflow-gpu版本

    # 使用哪个tensorflow版本都行
    conda create -n tf-gpu python=3.6 tensorflow-gpu
    
    # 比如使用tensorflow1.13版本
    conda create -n tf-gpu python=3.6 tensorflow-gpu=1.13
    
  • tensorflow-cpu版本

    conda create -n tf-cpu python=3.6 tensorflow
    
  • 说明:

    • create:是在conda中创建一个虚拟环境,
    • -n:后面的tf-gpu是虚拟环境的名字

安装keras

  • keras

    conda install keras
    

安装Pytorch

  • Pytorch-gpu版本

     conda create -n pyt-gpu python=3.6 pytorch torchvision cudatoolkit=10.1 -c pytorch
    
  • pytorch-cpu版本

     conda create -n pyt-cpu python=3.6 pytorch-cpu torchvision-cpu -c pytorch
    


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM