# Extending an existing Conda environment

An environment holds a Python interpreter and the packages it uses. Adding a package can also change shared dependencies. For a workshop or a working analysis, keep the original environment available and try the change in a named clone. Use `conda env list` to identify the target and `conda list --name ENV --revisions` to record the starting revision in the environment you will change. Substitute the actual environment name for `ENV`.

Run `conda install --name ENV --dry-run PACKAGE` before installing. The dry run resolves dependencies and displays the proposed transaction before applying package changes. Review additions, removals, version changes and channels, then check the plan again at the actual install prompt. A dependency conflict means the solver could not find a set of builds that meets the current requirements for the platform and channels. Check the conflicting package and its version bounds. A compatible package release or a fresh environment with compatible requirements can resolve the conflict. Test both the new feature and your original workflow after installing.

## Choosing Conda or pip

Conda resolves Python packages and other software such as Qt and compiled libraries from Conda channels. pip installs Python distributions, typically from PyPI, into the interpreter that runs it. Use Conda first for packages available through the course channels. If a Python package is available only through pip, install the Conda dependencies and pip first, then activate the intended environment and use `python -m pip`. Inspect the proposed pip changes with `python -m pip install --dry-run PACKAGE` and check Python dependency metadata afterward with `python -m pip check`. Use a clone or a fresh environment for that trial and run the original workflow afterward. If further Conda changes are needed after pip, prefer rebuilding from an updated YAML with the Conda dependencies and then the pip dependencies.

Conda records revisions for its own package transactions. You can use `conda install --name ENV --revision N` to restore one of those revisions. Conda's revision history does not undo pip installs or restore notebooks and data. A clean rebuild from a reviewed specification is the recovery route for mixed changes when the original environment is unavailable.

## Recording an environment

- Share a curated environment YAML with its channels, direct dependencies, useful version bounds and any pip requirements under `pip:`. Recreate it with `conda env create --file environment.yml`. Different operating systems and architectures may resolve different builds.
- Use `conda env export --name ENV --from-history > environment.yml` as a starting point for the Conda requests recorded in history. Review the result, remove any machine-specific `prefix:`, and put required pip dependencies back into the YAML. Start with the course YAML when available, since a clone's history can lack the original direct requests.
- Use `conda list --name ENV --explicit > conda-explicit.txt` to capture exact Conda builds. Use `conda create --name ENV-rebuilt --file conda-explicit.txt` on the same Conda platform when those builds are available. Record pip requirements separately and install them after Conda. Keep the environment file with the analysis code and record the platform you tested.

[Conda guide to managing environments](https://docs.conda.io/projects/conda/en/stable/user-guide/tasks/manage-environments.html) and [pip install reference](https://pip.pypa.io/en/stable/cli/pip_install/).
