Basic Setup and Tools

Conda Tutorial: Environment and Package Management

Apunte, 2 min de lectura.setup/conda_tutorial.md

En esta página
  1. 1. Installation
  2. 2. Managing Environments
  3. Create an Environment
  4. Activate and Deactivate an Environment
  5. List Environments
  6. Remove an Environment
  7. 3. Managing Packages
  8. Install Packages
  9. Install from other channels
  10. List Installed Packages
  11. Update Packages
  12. Remove Packages
  13. 4. Sharing Environments
  14. Export an Environment
  15. Create an Environment from a File

Conda is an open-source package and environment management system that runs on Windows, macOS, and Linux. It is widely used in the data science and machine learning communities.

1. Installation

We recommend installing Miniconda, a minimal installer for conda. It is smaller and faster to install than the full Anaconda distribution.

  1. Download the installer: Go to the Miniconda download page and download the appropriate installer for your operating system.

  2. Run the installer: Follow the instructions for your OS. It's recommended to allow the installer to initialize conda, which will make it available in your terminal.

  3. Verify installation: Open a new terminal and run:

    conda --version

    You should see the installed conda version.

2. Managing Environments

A conda environment is a directory that contains a specific collection of conda packages that you have installed.

Create an Environment

To create a new environment, use conda create. It's good practice to specify the Python version you want to use.

# Creates an environment named 'myenv' with Python 3.12
conda create --name myenv python=3.12

You can also install packages at the same time:

conda create --name myenv python=3.12 numpy pandas jupyter

Activate and Deactivate an Environment

Before you can use an environment, you need to activate it.

# Activate the environment
conda activate myenv

Your terminal prompt should change to show the name of the active environment.

To deactivate the current environment and return to the base environment:

# Deactivate the environment
conda deactivate

List Environments

To see a list of all your environments:

conda env list

The active environment will be marked with an asterisk (*).

Remove an Environment

To delete an environment and all the packages installed in it:

# Make sure the environment is not active
conda deactivate

# Remove the environment
conda env remove --name myenv

3. Managing Packages

With your environment activated, you can install, update, and remove packages.

Install Packages

Use conda install to install packages from the default Anaconda channel.

# Activate your environment first
conda activate myenv

# Install packages
conda install numpy pandas scikit-learn

You can also specify package versions:

conda install numpy=1.26.0

Install from other channels

Sometimes packages are not available in the default channel. A popular channel is conda-forge.

conda install -c conda-forge some-package

List Installed Packages

To see all packages installed in the current environment:

conda list

Update Packages

To update a specific package:

conda update numpy

To update all packages in the environment:

conda update --all

Remove Packages

To uninstall a package:

conda remove scikit-learn

4. Sharing Environments

You can share your environment with others by exporting its specification to a YAML file.

Export an Environment

  1. Activate the environment you want to export.
    conda activate myenv
  2. Export the environment to a file (commonly named environment.yml).
    conda env export > environment.yml

This file can be shared, and others can replicate your environment.

Create an Environment from a File

To create an environment from an environment.yml file:

conda env create -f environment.yml

This will create a new environment with the same name and packages as specified in the file.

Escribe al menos dos letras. Busca también dentro del código de los notebooks.