问题描述
我的 .gitlab-ci.yml 文件如下所示:
my .gitlab-ci.yml file looks like this:
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
好的,所以我使用的是 4.4 之后的 conda 版本,所以 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
然后我尝试编辑我的 .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 init 触及 .bashrc 文件.要重新初始化 shell,您可以获取它:
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.