Linux018 conda虚拟环境

1.conda的安装

conda的介绍及安装详见:Linux010 Miniconda安装及使用

2.虚拟环境 virtual environment

虚拟环境就是把一部分内容独立出来,独立出来这部分也被称作“容器”,在这个容器中可以只安装我们需要的依赖包,各个容器之间互相隔离,互不影响。

3.为什么要用虚拟环境

在实际使用过程中,我们通常会根据自己的需求不断的更新或卸载相应的库,直接对基础环境操作会造成很多不必要的麻烦,管理也相当混乱,另外就是如果出现了bug,想要恢复环境,也是很麻烦的过程。

4.conda虚拟环境操作

4.1 conda命令用法
  • conda命令
usage: conda [-h] [-V] command ...

conda is a tool for managing and deploying applications, environments and packages.

Options:

positional arguments:
  command
    clean        Remove unused packages and caches.
    compare      Compare packages between conda environments.
    config       Modify configuration values in .condarc. This is modeled
                 after the git config command. Writes to the user .condarc
                 file (/home/caoqiansheng/.condarc) by default.
    create       Create a new conda environment from a list of specified
                 packages.
    help         Displays a list of available conda commands and their help
                 strings.
    info         Display information about current conda install.
    init         Initialize conda for shell interaction. [Experimental]
    install      Installs a list of packages into a specified conda
                 environment.
    list         List linked packages in a conda environment.
    package      Low-level conda package utility. (EXPERIMENTAL)
    remove       Remove a list of packages from a specified conda environment.
    uninstall    Alias for conda remove.
    run          Run an executable in a conda environment. [Experimental]
    search       Search for packages and display associated information. The
                 input is a MatchSpec, a query language for conda packages.
                 See examples below.
    update       Updates conda packages to the latest compatible version.
    upgrade      Alias for conda update.

optional arguments:
  -h, --help     Show this help message and exit.
  -V, --version  Show the conda version number and exit.

conda commands available from other packages:
  env
  • conda-env
usage: conda-env [-h] {create,export,list,remove,update,config} ...

positional arguments:
  {create,export,list,remove,update,config}
    create              Create an environment based on an environment file
    export              Export a given environment
    list                List the Conda environments
    remove              Remove an environment
    update              Update the current environment based on environment
                        file
    config              Configure a conda environment

optional arguments:
  -h, --help            Show this help message and exit.

conda commands available from other packages:
  env
4.2 基本操作
## 创建新环境
conda create -n env_name python=version
## 激活
conda activate env_name 
## 查看
conda env list
## 退出
conda deactivate
## 删除
conda remove -n  env_name --all
## 查看安装了哪些包。
conda list
## 查看当前存在哪些虚拟环境
conda env list 
conda info -e
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。