在Python脚本中激活Conda环境

Wil*_*ill 7 python bash subprocess anaconda conda

我正在将shell脚本转换为Python,我正在寻找一种在Python中以编程方式激活和停用conda环境的方法.我查看了Github上的Conda代码,但未能找到一个好的解决方案.

我需要激活环境,以便我可以在其中运行多个语句.例如:

source activate my_env
easy_install numpy 
backup_db
initialize_db
source deactivate 
Run Code Online (Sandbox Code Playgroud)

我没有使用子进程的运气.:-(

tis*_*rum 1

这是一种迂回的方法,但是你不能让 python 直接调用脚本吗?

请参阅此问题以了解如何执行此操作

使用 python 代码运行 .bat 文件