【问题标题】:anaconda to run a script on the fly when activatinganaconda 在激活时即时运行脚本
【发布时间】:2020-02-02 22:11:13
【问题描述】:

我在 teamcity 配置中使用 Windows cmd 脚本作业。 Job 基本上是通过直接 python 调用来运行测试

set PYTHONPATH=c:\work;%PYTHONPATH;
cd c:\work\test
pytest -v

现在我们决定在 anaconda 环境中运行测试, 并寻找类似的东西

conda activate test_env -execute "wrapper.bat"

有什么想法吗?

【问题讨论】:

  • 这个@libxelar 运气好吗?

标签: teamcity pytest anaconda3


【解决方案1】:

这就是我在 Teamcity 中使用 conda 环境所做的工作

  1. 使用 powershell 构建步骤
  2. 创建 conda 环境并设置路径
conda create -y --name %conda_env_name% python=%python_version%

activate %conda_env_name%

# Created Conda paths to be added to path  
$conda_path = "C:\Program Files\Conda43\envs\" + "%conda_env_name%"
$conda_script = "$conda_path" + "\Scripts"
$conda_lib = "$conda_path" + "\Library\bin"

# Add the newly conda to your path for the session only
$env:Path = "$conda_path;$conda_script;$conda_lib;$env:Path"

#test that it is now using python from the new conda env together with pip
python -V
pip -V
  1. 就是这样,运行并测试它

【讨论】:

  • activate 已经将环境添加到路径中,无需手动执行此操作(即看起来这两次执行相同操作)
猜你喜欢
  • 2019-08-19
  • 1970-01-01
  • 1970-01-01
  • 2019-06-07
  • 2016-07-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-27
相关资源
最近更新 更多