Create, share, and manage named environments in Conda v2
Named environments in Conda v2 work like Docker tags - they provide human-readable aliases for fully resolved environments, making it easy to share and version your dependency configurations.
A named environment is an alias for a fully resolved environment. Instead of referring to an environment by its 40-character hexadecimal hash, you can use a memorable name like mlp/metaflow/data_science_env:v1.
Named environments are similar to Docker image tags. Just as python:3.9 points to a specific Docker image, my_team/my_env:v1 points to a specific resolved Conda environment.
Use these for “rolling” environments that should track the latest version.
Once you alias an environment with an immutable tag, you cannot change that alias to point to a different environment. You must use a new tag (e.g., :v2 instead of :v1).
@named_env(name="@{TEAM}/my_project/@{ENV_NAME}:@{VERSION}")@stepdef my_step(self): # Environment name is constructed from: # TEAM, ENV_NAME, and VERSION environment variables pass
export TEAM="mlp"export ENV_NAME="training_env"export VERSION="v2"python myflow.py --environment=conda run
For mutable tags, fetch the latest version at execution time:
@named_env( name="my_team/my_env:latest", fetch_at_exec=True)@stepdef my_step(self): # Always uses the current :latest environment # when this step executes (not when flow is deployed) pass
fetch_at_exec=True is useful for development environments that should always use the latest packages, but be cautious in production as it can affect reproducibility.
You can reference any previously executed step’s environment using its pathspec:
@named_env(pathspec="TrainingFlow/456/train")@stepdef inference(self): # Uses the exact environment from TrainingFlow/456/train pass
Pathspecs are automatically treated as aliases:
# Show environment for a pathspecmetaflow environment show --pathspec MyFlow/123/train# Create local environment from pathspecmetaflow environment create --pathspec MyFlow/123/train --name my_env
Includes all packages from numpy_test_env:v1 with locked versions
Adds itsdangerous=2.1.2
Gets a new alias numpy_danger_env:v1
Extending does not modify the original environment. It creates a new environment. All locked dependencies from the base environment are preserved - you cannot add incompatible packages.
DEFAULT Environment of type conda-only full hash d49465b2b45996e40aad1f3aaf00cba553a0f085:f671c941b27764ad6536f7fdadc6c57b18221c6eAliases mlp/metaflow/conda_example/numpy_test_env:latest (mutable)Arch linux-64Available on linux-64Resolved on 2023-09-06 07:16:01.794427Resolved by romainLocally present as /usr/local/libexec/metaflow-condav2-20230809/envs/metaflow_d49465b2b45996e40aad1f3aaf00cba553a0f085_f671c941b27764ad6536f7fdadc6c57b18221c6eUser-requested packages conda::boto3==>=1.14.0, conda::numpy==1.21.5, conda::pandas==>=0.24.0, ...User sources conda::conda-forgeConda Packages installed _libgcc_mutex==0.1-conda_forge, numpy==1.21.5, pandas==2.0.3, ...
Best practice: Use immutable version tags (:v1, :v2) in production flows to ensure reproducibility. Use mutable tags (:latest, :stable) only in development or when you explicitly want rolling updates.
class InferenceFlow(FlowSpec): @named_env(name="ml_team/training/sklearn_env:v1") @step def predict(self): # Uses exact same environment as training pass