In the Python ecosystem, it is customary to find a requirements.txt
file accompanying most packages. However, when managing individual projects, an alternative approach often proves more beneficial - exporting the conda environment into an environment.yaml
file instead of utilizing a requirements.txt
.
conda env export --no-builds | grep -v "^prefix: " > environment.yaml
This command can be dissected into three components:
conda env export --no-builds
: This segment of the command exports all the specifics of the current conda environment. The inclusion of--no-builds
ensures that only the names and versions of packages are exported, excluding any build specifications.grep -v "^prefix: "
: This part filters out the line specifying the path to the environment, which can differ across various machines.> environment.yaml
: This redirects the output into a file namedenvironment.yaml
.
The resulting environment.yaml
file provides a comprehensive snapshot of your conda environment, encapsulating all installed packages along with their precise versions. This proves invaluable when sharing your environment with others or recreating it on a different machine.
Contrary to a requirements.txt
file, an environment.yaml
file can also encompass details about non-Python packages. This makes it a robust solution for intricate projects that require a diverse set of tools and libraries.