首页 > 解决方案 > 在 conda 环境中在 circleci 运行测试

问题描述

我使用 conda,并试图弄清楚如何在 circleci 上运行。我有一个非常简单的项目,环境中调用calculator了两个函数(每个函数一个addition,一个subtraction和一个测试)。我pylint8用来检查格式,和pytest/pytest-cov用于测试/覆盖。

我的配置文件如下,它似乎一直在工作,直到我到达测试运行阶段:

# Python CircleCI 2.0 configuration file
version: 2
jobs:
  build:
    docker:
      - image: continuumio/miniconda3

    working_directory: ~/repo

    steps:
      # Step 1: obtain repo from GitHub
      - checkout
      # Step 2: create virtual env and install dependencies
      - run:
          name: install dependencies
          command: |
            conda env create -f environment.yml

      # Step 3: run linter and tests
      - run:
          name: run tests
          command: |
            conda init bash
            conda activate calculator
            flake8 --statistics
            pytest -v --cov

第 1 步和第 2 步工作正常,但第 3 步失败,并显示以下消息:

#!/bin/bash -eo pipefail
conda init bash
conda activate calculator
flake8 --statistics
pytest -v --cov
no change     /opt/conda/condabin/conda
no change     /opt/conda/bin/conda
no change     /opt/conda/bin/conda-env
no change     /opt/conda/bin/activate
no change     /opt/conda/bin/deactivate
no change     /opt/conda/etc/profile.d/conda.sh
no change     /opt/conda/etc/fish/conf.d/conda.fish
no change     /opt/conda/shell/condabin/Conda.psm1
no change     /opt/conda/shell/condabin/conda-hook.ps1
no change     /opt/conda/lib/python3.7/site-packages/xontrib/conda.xsh
no change     /opt/conda/etc/profile.d/conda.csh
modified      /root/.bashrc

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


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

我在 Ubuntu 18 中。我之前没有运行conda init bash,但基于错误,我把它放在那里,但它仍然建议我初始化我的 shell,即使我已经这样做了。

标签: pythonanacondacircleci

解决方案


conda init bash更改您的.bashrc,然后必须重新加载。

你可以按这个顺序试试

conda init bash
source ~/.bashrc
conda activate calculator

或者干脆尝试老式的方式source activate calculator(根本不运行conda init bash)。


推荐阅读