Anaconda virtual environment usage and package management

Anaconda virtual environment usage and package management

Foreword:

pass

Reference link:

Anaconda virtual environment usage and package management

List all existing virtual environments

conda env list
conda info -e

Create a new virtual environment

conda create -n env_name python=version

Activate and enter the virtual environment

conda activate env_name

Delete an existing virtual environment (the following two commands are acceptable)

conda env remove -n env_name
conda remove –name env_name –all

When sharing code, you also need to share the operating environment with everyone

You have to activate the corresponding environment first, and then export. Note that the env below is env, which has nothing to do with the environment name.

conda env export > env.yaml

Use the YAML file shared by the other party to create exactly the same operating environment

You can modify the environment name and path:

name: env_name
...
prefix: /home/origin_user_name/anaconda3/envs/env_name

become:

name: new_env_name
...
prefix: /home/new_user_name/anaconda3/envs/new_env_name

Instructions for re-creating the environment: Note that there is no need to specify the environment name, because it is given in the yaml file.

conda env create -f env.yaml

Jupyter runs Anaconda's virtual environment

source activate env_name
conda install ipykernel (注意:在虚拟环境中安装ipykernel)
python -m ipykernel install --name env_name --display-name "env_name" (

Enter Jupyter's kernel:

jupyter notebook

Jupyter-Notebook delete the specified kernel

--View which kernels are in jupyter notebook

jupyter kernelspec list

-Delete the specified kernel

jupyter kernelspec remove kernel_name

Manage anaconda packages

-Manage the package of the specified virtual environment

conda install package_name -n env_name
conda install package_name
conda install pack=version (指定安装包的版本)

--Specify the installation package through requirement.txt

conda install --yes --file requirement.txt

Or install requirement.txt with pip:

pip install -r requirement.txt

-Batch export requirement.txt of all packages in the environment

conda list -e > requirement.txt

or

pip freeze > requirement.txt

--Delete anaconda specific package

conda remove package_name

--Update anaconda specific packages

conda update package_name

-Search for anaconda specific package

conda search package_name

Guess you like

Origin blog.csdn.net/hehedadaq/article/details/113103721