Anaconda is a distribution that allows you to set up Python itself along with libraries frequently used for data analysis and scientific computing, such as NumPy, pandas, and Matplotlib, all at once. To manage these, we use the conda command.
Below, I have systematically organized the major commands, ranging from building virtual environments to package management. This guide is summarized in a format ready for practical use.
Table of Contents
- Creating Virtual Environments (
conda create) - Operating Virtual Environments (
activate/info/remove) - Package Management (
install/update/remove) - Saving and Reproducing Environments (Export)
- Output current environment configuration to file
- Reproduce (create) environment from file
- Note: Using pip and conda together
1. Creating Virtual Environments (conda create)
Create a new virtual environment to isolate Python versions and libraries for each project.
| Purpose | Command |
| Create specifying packages | conda create --name <env_name> <package_name> |
| Create specifying Python version | conda create --name <env_name> python=3.9 |
| Clone an existing environment | conda create --name <env_name> --clone <source_env> |
| Clone the base environment | conda create --name <env_name> --clone base |
Execution Example: Creating an environment named data_analysis containing Python 3.10 and pandas.
conda create --name data_analysis python=3.10 pandas
2. Operating Virtual Environments (activate / info / remove)
To use a created environment, you need to switch to it (activate it).
| Purpose | Command |
| Activate environment | conda activate <env_name> |
| Deactivate (Return to base) | conda deactivate |
| List created environments | conda info --envs |
| Delete environment | conda remove --name <env_name> --all |
Supplement: In the output of conda info --envs, the environment marked with * is the currently active environment.
3. Package Management (install / update / remove)
Add or update libraries. Basically, this is done for the active environment, but it can also be specified externally using the --name option.
| Purpose | Command |
| Search for a package | conda search <keyword> |
| Install a package | conda install --name <env_name> <package_name> |
| Update a package | conda update --name <env_name> <package_name> |
| Update conda itself | conda update conda |
| Uninstall a package | conda remove --name <env_name> <package_name> |
| Check installed packages | conda list --name <env_name> |
Execution Example: Installing scikit-learn into the current environment.
conda install scikit-learn
4. Saving and Reproducing Environments (Export)
Use this when you want to build the same environment for team members or migrate the environment to another machine.
Output current environment configuration to file
Write the list of installed packages to a text file.
conda list --name <env_name> --export > package-list.txt
Note: The following command, which outputs in YAML format to improve compatibility between OSs, is also frequently used.
conda env export --name <env_name> > environment.yml
Reproduce (create) environment from file
Build a new environment based on the output file.
conda create --name <new_env_name> --file package-list.txt
Note: Using pip and conda together
Within an Anaconda environment, prioritize using conda install as a general rule. Use pip install only for packages that are not provided by conda. Mixing these disorderly can break dependencies and cause the environment to malfunction.
