export conda environment without prefix variable which shows local path to executable

This question was already addressed here, but without a real explanation on the role of prefix.
At least there is a solution to exclude the prefix line programmatically.

It is not mentioned in the conda doc, except for the fact that conda env export --prefix PATH allows to specify a prefix.
But note that --name and --prefix options are exclusive here.

If you have a look at conda‘s code, you’ll see that conda create refers to cli_install.check_prefix(). And that install.py seems to indicate that there is a safety check on the environment name (extracted from the prefix) and on the full prefix path in order to ensure that no environment exists with the same name or path.

from conda/cli/install.py

def check_prefix(prefix, json=False):
    name = basename(prefix)
    error = None
    if name == ROOT_ENV_NAME:
        error = "'%s' is a reserved environment name" % name
    if exists(prefix):
        if isdir(prefix) and 'conda-meta' not in os.listdir(prefix):
            return None
        error = "prefix already exists: %s" % prefix

    if error:
        raise CondaValueError(error, json)

    if ' ' in prefix:
        stderrlog.warn("WARNING: A space was detected in your requested environment path\n"
                       "'%s'\n"
"Spaces in paths can sometimes be problematic." % prefix)

My guess is that this prefix in environment.yaml is part of a complex strategy to ensure conda will know where to create the environment. But it seems it is useless in most cases, and probably its presence is only due to the mechanistic link between --name and --prefix.

from conda.base.context.py Context()

# This block of code sets CONDA_PREFIX based on '-n' and '-p' flags, so that
# configuration can be properly loaded from those locations

EDIT:

The fact that prefix is not even mentioned in the “creating an environment file manually” section of the conda doc is comforting in the idea that this line is useless…

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)