conda激活Travis CI

问题描述 投票:2回答:1

我正在使用conda 4.6.8在Travis CI的conda env中测试python包。我想在我的Travis CI配置中用新的source activate ENVNAME conda activate ENVNAME替换旧的command线。如果我在Travis上运行:

>>> conda update -n base conda
>>> conda init
no change     /home/travis/miniconda/condabin/conda
no change     /home/travis/miniconda/bin/conda
no change     /home/travis/miniconda/bin/conda-env
no change     /home/travis/miniconda/bin/activate
no change     /home/travis/miniconda/bin/deactivate
no change     /home/travis/miniconda/etc/profile.d/conda.sh
no change     /home/travis/miniconda/etc/fish/conf.d/conda.fish
no change     /home/travis/miniconda/shell/condabin/Conda.psm1
no change     /home/travis/miniconda/shell/condabin/conda-hook.ps1
no change     /home/travis/miniconda/lib/python3.7/site-packages/xonsh/conda.xsh
no change     /home/travis/miniconda/etc/profile.d/conda.csh
modified      /home/travis/.bashrc
==> For changes to take effect, close and re-open your current shell. <==

如何在特拉维斯“关闭并重新打开”我的外壳?因为否则我无法激活我的conda环境:

>>> conda create -n TEST package_names
>>> conda activate TEST
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
    $ conda init <SHELL_NAME>
Currently supported shells are:
  - bash
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
The command "conda activate TEST" failed and exited with 1 during .
Your build has been stopped.
bash shell anaconda travis-ci conda
1个回答
1
投票

不确定它目前是否支持官方文档still uses source in travis.yml

What does conda init do?

这个新命令应该协调用户设置shell的方式,以便能够调用conda activate

实际上,如果你运行conda init --dry-run --verbose,你会看到它试图从你的conda.sh中获取~/.bashrc(假设你正在运行Bash,来自你问题中提到的信息)。

并且conda.sh将定义一个conda()函数,它将捕获一些命令,其中activatedeactivate并发送到$CONDA_EXE

conda() {
    if [ "$#" -lt 1 ]; then
        "$CONDA_EXE"
    else
        \local cmd="$1"
        shift
        case "$cmd" in
            activate|deactivate)
                __conda_activate "$cmd" "$@"
                ;;
            install|update|upgrade|remove|uninstall)
                "$CONDA_EXE" "$cmd" "$@" && __conda_reactivate
                ;;
            *) "$CONDA_EXE" "$cmd" "$@" ;;
        esac
    fi
}

因此,除非在本地shell中定义此函数,否则您将无法调用conda activate

Hint on a solution? (not tested for Travis CI)

我建议的唯一提示是尝试source $(conda info --root)/etc/profile.d/conda.sh然后conda activate。假设您正在使用Bourne shell派生词,这应该与conda init大致相同。

csh$(conda info --root)/etc/profile.d/conda.cshfish$(conda info --root)/etc/fish/conf.d/conda.fish

注意:虽然没有针对Travis CI进行测试,但这个解决方案对我来说是bash。当然,conda可执行文件应该在PATH中找到,以便conda info --root正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.