conda虛擬環境安裝


一、背景

  需要學習mxnet,建一個conda虛擬軟件環境。

二、步驟

1、下載anaconda安裝文件:https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/

wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.3.1-Linux-x86_64.sh

2、安裝:

bash  Anaconda3-5.3.1-Linux-x86_64.sh

3、驗證conda是否成功

conda -V

4、下載d2lzh.zip包

wget https://zh.d2l.ai/d2l-zh-1.1.zip

5、新建d2lzl目錄,並把d2l-zh-1.1.zip拷貝到該目錄進行解壓

unzip d2l-zh-1.1.zip

6、修改conda軟件源,以方便虛擬環境構建

在.conda隱藏目錄下新建隱藏文件.condarc,內容如下:

channels:
  - defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
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
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
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

7、使用conda clean -i命令清除索引緩存,保證用的是鏡像站提供的索引。

8、進入d2lzh目錄,執行虛擬環境建立命令:

conda env create -f environment.yml

9、進入虛擬環境

conda activate gluon

10、退出虛擬環境

conda deactivate

11、運行jupyter note命令:

jupyter notebook --allow-root --no-browser --port=8888 --ip=0.0.0.0

12、若干章節的代碼會自動下載數據集和預訓練模型,並默認使用美國站點下載。為方便下載,宜把下載站點地址變量MXNET_GLUON_REPO修改為國內站點地址。

方法一:在運行Jupyter前指定MXNet使用國內站點

export MXNET_GLUON_REPO=https://apache-mxnet.s3.cn-north-1.amazonaws.com.cn/ jupyter notebook

方法二:修改用戶目錄下.bash_profile文件,把上述命令添加到該文件最后,此法不用每次運行jupyter notebook命令前指定變量。

(gluon) [root@localhost ~]# vi .bash_profile

...

export MXNET_GLUON_REPO=https://apache-mxnet.s3.cn-north-1.amazonaws.com.cn/ jupyter notebook

 

激活環境變量:

(gluon) [root@localhost ~]# source .bash_profile

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM