diff --git a/lib/spack/spack/environment/environment.py b/lib/spack/spack/environment/environment.py index 25fbcd59550..01516004979 100644 --- a/lib/spack/spack/environment/environment.py +++ b/lib/spack/spack/environment/environment.py @@ -65,6 +65,10 @@ #: default path where environments are stored in the spack tree default_env_path = os.path.join(spack.paths.var_path, "environments") +# ensure that this base directory exists since we require the root directory to be created +# in our checks +os.makedirs(default_env_path, exist_ok = True) + #: Name of the input yaml file for an environment manifest_name = "spack.yaml" @@ -250,6 +254,8 @@ def create(name, init_file=None, with_view=None, keep_relative=False): """Create a named environment in Spack.""" if not os.path.isdir(env_root_path()): # double check that the root path exists before we check the full environment name + # we need to be a bit more pedantic and not create automatically since this is a user + # configurable path that can be subject to user input errors raise SpackEnvironmentError( "The environments_root '{er}' does not exist. Please create the directory or provide " "a valid path in the config.yaml".format(er=env_root_path())