Environment/Anaconda

create, activate, deactivate, install, info --envs, list, forge, remove

Naranjito 2021. 1. 4. 18:06

Conda is a data science specialized python distribution, comprehensive package and environment management tool

we can create isolated environments for our projects, and these projects can have different packages and even distinct Python versions.

reference : towardsdatascience.com/8-essential-commands-to-get-started-with-conda-environments-788878afd38e

https://m.blog.naver.com/sarang2594/221310545963 

 

  • conda

It returns the available tool for managing and deploying applications, environments and packages.

$ conda
usage: conda [-h] [-V] command ...

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

...

conda commands available from other packages:
  build
  convert
  
...

 

  • conda --version

The prompt shows you the version of the conda.

$ conda --version
conda 4.9.2

 

  • conda env list

Find out what environments are available.

$ conda env list
# conda environments:
#
base                  *  /Users/joohyunyoon/opt/anaconda3
scenario                 /Users/joohyunyoon/opt/anaconda3/envs/scenario
text_spec                /Users/joohyunyoon/opt/anaconda3/envs/text_spec

base : the default environment that conda has created for us during its installation.

asterisk(*) : indicates that this particular environment is the active one.

 

  • conda create -n DL

Create anaconda environment named DL.

-n or --name : name

$ conda create -n DL
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /Users/joohyunyoon/opt/anaconda3/envs/DL



Proceed ([y]/n)? y

Preparing transaction: done

...

 

  • conda activate DL

Activate the environment. Once you run this, you should notice that the prompt has been prefixed with (your-own-env-name)

$ conda activate DL
(DL)

 

  • conda install pandas

It tries installing the package from the default channel anaconda. 

$ conda install pandas
Collecting package metadata (current_repodata.json): done
Solving environment: done
...
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

 

  • conda install -c conda-forge opencv

If the default anaconda channel may not have the specific package, you can try another common channel called conda-forge. 

The channel where the package is to be fetched.

$ conda install -c conda-forge opencv
Collecting package metadata (current_repodata.json): done
Solving environment: done
...
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

 

  • conda uninstall pandas
conda uninstall pandas
...
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

 

  • conda info --envs

Get a list of all my environments information.

$ conda info --envs
# conda environments:
#
base                     /Users/joohyunyoon/opt/anaconda3
DL                    *  /Users/joohyunyoon/opt/anaconda3/envs/DL

 

  • conda list

Get all the packages in environment at the root where conda installed. It shows you from which channel the packages are installed. If there is no channel information, it means that the packages are installed from the default channel (anaconda).

$ conda list
r-chords                  0.95.4            r36h6115d3f_0  
r-lattice                 0.20_38           r36h46e59ec_0  
r-mass                    7.3_51.3          r36h46e59ec_0  
r-matrix                  1.2_17            r36h46e59ec_0  
readline                  7.0                  h1de35cc_5  
requests                  2.25.1             pyhd3deb0d_0    conda-forge

...

 

  • conda list opencv

If the list is too long to spot a particular package, you can check the information for a single package.

$ conda list opencv
# packages in environment at /Users/joohyunyoon/opt/anaconda3/envs/scenario:
#
# Name                    Version                   Build  Channel
libopencv                 4.5.1            py39h1742fbf_1    conda-forge
opencv                    4.5.1            py39h6e9494a_1    conda-forge
py-opencv                 4.5.1            py39h71a6800_1    conda-forge

 

  • conda deactivate

It’ll notice that the prefix (DL) is removed from the command line's prompt. 

(DL) $ conda deactivate
$ 

 

  • conda env > environment.yml

Sharing environments. This will create a requirement file in your current directory that lists the current environment's information, such as name, dependencies, and installation channels. It is just a text file.

$ conda env > environment.yml

 

  • conda env create -f environment.yml

You share this file with those who want to reproduce this environment

conda env create -f environment.yml

-f : flag, It indicates that we want to tcreate an environment from the specified file. If you've navigated to the directory, where the environment.yml is located, you can simply run conda env create.

 

  • conda env remove -n
conda env remove -n ENV_NAME

'Environment > Anaconda' 카테고리의 다른 글

conda update  (0) 2022.03.02
Environment Configuration  (0) 2021.11.02
How to connect Jupyter through Anaconda.  (0) 2021.11.01