一、基本使用
1. 创建和安装
创建flye环境
安装numpy包到flye环境
conda install -n flye numpy
创建一个名为flye的环境,并安装Python版本3.6(conda自动寻找3.6.x中最新版本)
conda create -n flye python=3.6
2. 使用
安装好后,使用activate激活某个环境
source activate flye
conda activate flye (更新conda可使用)
退出已激活的环境
source deactivate flye
conda deactivate flye (更新conda可使用)
3. 删除
删除flye环境和其环境所有的包
conda remove -n flye --all
移除flye环境的 Sambamba
conda remove -n flye sambamba
4. 查看
查看当前存在的环境
conda info --envs
查看已经安装的packages
【最新版的conda是从site-packages文件夹中搜索已经安装的包,不依赖pip,因此可以显示出通过各种方式安装的包】
conda list
查看flye环境中已安装包
conda list -n flye
5. 更新
更新conda,保持conda最新
conda update conda
更新flye中的numpy包
conda update -n flye numpy
6. 配置
添加环境
conda config --add envs_dirs /opt/anaconda/envs/flye_test
=========================================================================
二、高级用法
1. 复制环境到新电脑或者用户(clone)
输出环境信息到文本
conda env export -n hicExplorer > environment.yml
依照文本信息重新生成一个同样环境
conda env create -f environment.yml
比如
依照文本信息重新生成 training环境
conda env create -n training -f environment.yml
2. root安装一次,多用户共享
参考(验证是正确的):http://www.dxulab.org/wiki/anacondaenvformulti-users
sudo su -
adduser anaconda
bash Anaconda3-2019.03-Linux-x86_64.sh -b -p /opt/anaconda
chown -R anaconda:anaconda /opt/anaconda
chmod -R go-w /opt/anaconda
chmod -R go+rX /opt/anaconda
# And then you can put /opt/anaconda/bin in the PATH added in /etc/profiles.d/anaconda.sh (or wherever). A (very) nice thing about Anaconda is that it requires no environment variables to be set. Adding it to your PATH is just for convenience.
# You (as the sudo-empowered admin) can then go and create new environments for all users on the system:
sudo -u anaconda /opt/anaconda/bin/conda env create -n flye_test -c bioconda flye
sudo -u anaconda /opt/anaconda/bin/conda env create -n training -f environment.base.yml
# And then any user, say janesmith can go and use these:
source activate coolscience # will add /opt/anaconda/envs/coolscience/bin to PATH
# Additionally they can create their own envs:
conda create -n webdev django flask sqlalchemy pylons
# which will (should) be created in ~janesmith/.conda/envs/webdev.
# I have tested exactly 0% of the commands above, but they should point you in the right direction. Additionally, I must note, Conda is known to have “gotchas” that can come up when using it in a multi-user environment like this. A partial record of the challenges you may face are recorded in this issue:
3. root安装一次,多用户共(无患子服务器),发现无需新增用户anaconda
以及将文件归属anaconda
,普通用户也能成功调用
sudoer 用户切换后,运行如下命令:
sudo -s
bash Anaconda3-2019.03-Linux-x86_64.sh -b -p /opt/anaconda
其中environment.flye.yml
和environment.base.yml
是在虚拟机中环境的导出文件
conda env export -n flye > environment.flye.yml
conda env export -n base > environment.base.yml
依照创建创建环境flye_test
和training
,
/opt/anaconda/bin/conda env create -n flye_test -f environment.flye.yml
/opt/anaconda/bin/conda env create -n training -f environment.base.yml
普通用户调用环境
方法1:
进入某个环境source /opt/anaconda/bin/activate flye_test
[junting_feng@localhost ~]$ /opt/anaconda/bin/conda info --envs
# conda environments:
#
base * /opt/anaconda
flye_test /opt/anaconda/envs/flye_test
[junting_feng@localhost ~]$ source /opt/anaconda/bin/activate flye_test
(flye_test) [junting_feng@localhost ~]$
退出当前环境source /opt/anaconda/bin/deactivate
,忽略报错
(flye_test) [smrtanalysis@localhost ~]$ source /opt/anaconda/bin/deactivate
DeprecationWarning: 'source deactivate' is deprecated. Use 'conda deactivate'.
[smrtanalysis@localhost ~]$
方法2:
执行/opt/anaconda/bin/conda activate flye_test
遇到如下报错:
[zaohai_zeng@localhost ~]$ /opt/anaconda/bin/conda activate flye_test
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
Currently supported shells are:
- bash
- fish
- tcsh
- xonsh
- zsh
- powershell
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
按照提示运行 /opt/anaconda/bin/conda init
命令,将conda写入.bashrc
文件
(base) [zaohai_zeng@localhost ~]$ /opt/anaconda/bin/conda init
no change /opt/anaconda/condabin/conda
no change /opt/anaconda/bin/conda
no change /opt/anaconda/bin/conda-env
no change /opt/anaconda/bin/activate
no change /opt/anaconda/bin/deactivate
no change /opt/anaconda/etc/profile.d/conda.sh
no change /opt/anaconda/etc/fish/conf.d/conda.fish
no change /opt/anaconda/shell/condabin/Conda.psm1
no change /opt/anaconda/shell/condabin/conda-hook.ps1
no change /opt/anaconda/lib/python3.7/site-packages/xontrib/conda.xsh
no change /opt/anaconda/etc/profile.d/conda.csh
modified /home/zaohai_zeng/.bashrc
==> For changes to take effect, close and re-open your current shell. <==
4. 退出,并重新登录
进入环境 conda activate flye_test
(base) [zaohai_zeng@localhost ~]$ conda activate flye_test
(flye_test) [zaohai_zeng@localhost ~]$
退出环境 conda deactivate
(flye_test) [zaohai_zeng@localhost ~]$ conda deactivate
(base) [zaohai_zeng@localhost ~]$
网友评论