使用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