在gitlab CI中激活conda环境 [英] Activating conda environment during gitlab CI

查看:141
本文介绍了在gitlab CI中激活conda环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 .gitlab-ci.yml 文件如下所示:

anomalydetector:
  image: continuumio/miniconda:4.7.10
  stage: build
  tags:
    - docker
  script:
    - conda env create -f environment.yml
    - conda activate my-env
    - pytest tests/.

在Gitlab上,此工作开始正常,并且日志已读取

On Gitlab, this job starts fine, and the logs read

$ conda env create -f environment.yml
Collecting package metadata (repodata.json): ...working... done
Solving environment: ...working... done


==> WARNING: A newer version of conda exists. <==
  current version: 4.7.10
  latest version: 4.7.11

好,所以我使用的是 conda 的版本晚于4.4,因此 conda activate 应该可以工作.但是,作业失败并显示以下内容:

Ok, so I'm using a conda version later than 4.4, so conda activate should work. However, the job fails with the following:

# To activate this environment, use
#
#     $ conda activate my-env
#
# To deactivate an active environment, use
#
#     $ conda deactivate

$ conda activate my-env

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

    $ conda init <SHELL_NAME>

然后我尝试编辑我的 .gitlab-ci.yml 文件,以便有一个命令

I have then tried editing my .gitlab-ci.yml file so that there is a command

conda init bash

但随后收到消息

==> For changes to take effect, close and re-open your current shell. <==

如何在gitlab CI流程中激活我的conda环境?

How can I activate my conda environment in the gitlab CI process?

推荐答案

conda初始化触摸 .bashrc 文件.要重新初始化外壳,您可以获取它:

conda init touches the .bashrc file. To reinitialize the shell you can source it:

  - conda create --name myenv
  - conda init bash
  - source ~/.bashrc    # <- !!!
  - conda activate myenv 

我想这是否比 source Activate myenv 好还是坏,这是一个单独的讨论.

Whether this is better or worse than source activate myenv is a separate discussion, I guess.

这篇关于在gitlab CI中激活conda环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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