导出conda环境,不带前缀变量,该变量显示可执行文件的本地路径 [英] export conda environment without prefix variable which shows local path to executable

查看:814
本文介绍了导出conda环境,不带前缀变量,该变量显示可执行文件的本地路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了在整个团队中实现可重复的改进,我将conda环境文件导出到了新创建的运行conda env export > environment.yml的存储库中.

In order to improve reproducibly across my team I have exported a conda environment file in a newly created repository running conda env export > environment.yml.

这个想法是让我的同事下载仓库并运行conda env create -f environment.yml并准备使用代码.

The idea is for my colleagues to download the repo and run conda env create -f environment.yml and be ready to use the code.

但是,我的一些同事向我指出,在yaml文件的底部有:

However, some of my colleagues pointed out to me that at the bottom of the yaml file there is:

  - readline=7.0=hc1231fa_4
  - requests=2.18.4=py35h0d65e6b_1
  - setuptools=38.5.1=py35_0
  - six=1.11.0=py35h39a4c60_1
  - sqlite=3.22.0=h3efe00b_0
  - tk=8.6.7=h35a86e2_3
  - urllib3=1.22=py35he002d57_0
  - wheel=0.30.0=py35h5c0b906_1
  - xz=5.2.3=h0278029_2
  - zlib=1.2.11=hf3cbc9b_2
prefix: </path/to/your/anaconda/distribution>/envs/<env-name>/bin

最后一个带有prefix变量的行实际上显示了我的机器名称和miniconda安装的唯一路径.

the last line with prefix variable actually shows my machine name and unique path to miniconda installation.

当我的同事们尝试加载环境时,脚本实际上对他们来说很好用,这意味着prefix变量基本上被conda忽略.

When my colleagues tried to load the environment the script actually works fine for them, which means that the prefix variable is basically ignored by conda.

我以前使用过virtualenvs,而我的绝对路径进入一个文件(该文件应该共享以使事情在不同的机器上可重现)的想法确实让我感到困惑.

I used to work with virtualenvs and the idea that my absolute path goes into a file which is supposed to be shared to make things reproducible on different machines really confounds me.

所以我的问题是:前缀变量是用来做什么的,有没有办法导出没有它的conda环境文件?

So my question is: what is the prefix variable used for and is there a way to export a conda environment file without it?

推荐答案

此问题已在此处,但没有对prefix的作用进行真正的解释. 至少有一种解决方案可以以编程方式排除前缀行.

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.

conda doc 中未提及.因为conda env export --prefix PATH允许指定前缀. 但是请注意,此处--name--prefix选项是排他的.

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.

如果看一下conda的代码,您会看到conda create指的是cli_install.check_prefix().而且 install.py 似乎表明那里是对环境名称(从prefix提取)和完整的prefix路径的安全检查,以确保不存在具有相同名称或路径的环境.

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.

来自conda/cli/install.py

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)

我的猜测是,environment.yaml中的prefix是确保conda知道在何处创建环境的复杂策略的一部分.但这似乎在大多数情况下是没有用的,并且它的存在可能仅是由于--name--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 it's presence is only due to the mechanistic link between --name and --prefix.

来自conda.base.context.py Context()

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


prefix的事实-manually"rel =" noreferrer>手动创建环境文件",conda文档的这一部分使人们感到欣慰的是,该行是无用的...

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...

这篇关于导出conda环境,不带前缀变量,该变量显示可执行文件的本地路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆