python - 在 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,即使我已经这样做了。
解决方案
conda init bash
更改您的.bashrc
,然后必须重新加载。
你可以按这个顺序试试
conda init bash
source ~/.bashrc
conda activate calculator
或者干脆尝试老式的方式source activate calculator
(根本不运行conda init bash
)。
推荐阅读
- python-3.x - 使派生类的方法异步
- python - 数据框写入 Postgresql 性能不佳
- ruby-on-rails - Papertrail 10.2.1 类的未定义方法“timestamp_sort_order”
- powerbi - 如何使用 power bi 计算平均值
- javascript - 如何从场景中移除对象
- python-3.x - TypeError:androlyze_main() 接受 2 个位置参数,但给出了 4 个
- dataframe - 删除数据框条件的行
- jenkins - Jenkins Groovy:给定 SSH 私钥,如何获取 SSH 公钥和/或密钥签名?
- arrays - 如何使用显示方法从构造函数显示数组?
- sql-server - 同事无法查询 SSISDB