为什么我的批处理脚本在激活新的conda env后停止了?

时间:2017-03-09 10:48:40

标签: batch-file conda miniconda

这足以重现这个问题:

另存为test.bat

:: Create Conda env
set name=%1
conda create -n %name% python -y
activate %name%
echo "Never gets here"
:: script should continue below...

从cmd运行。

>test.bat "testname"

输出:

C:\Users\Jamie\git>test.bat testname

C:\Users\Jamie\git>set name=testname

C:\Users\Jamie\git>conda create -n testname python -y
Fetching package metadata ...........
Solving package specifications: .

Package plan for installation in environment C:\Users\Jamie\Miniconda2\envs\testname:

The following NEW packages will be INSTALLED:

    pip:            9.0.1-py27_1
    python:         2.7.13-0
    setuptools:     27.2.0-py27_1
    vs2008_runtime: 9.00.30729.5054-0
    wheel:          0.29.0-py27_0

#
# To activate this environment, use:
# > activate testname
#
# To deactivate this environment, use:
# > deactivate testname
#
# * for power-users using bash, you must source
#


C:\Users\Jamie\git>activate testname

(testname) C:\Users\Jamie\git>

就是这样。 echo语句不会执行,但没有错误消息。

为什么激活conda env会暂停批处理脚本,是否有办法绕过它?

2 个答案:

答案 0 :(得分:12)

使用

call activate %name%
  • 我假设activate是批处理文件。如果你call,那么处理将在批处理完成后返回。如果没有call,执行会转移到activate,并在activate结束时结束。

答案 1 :(得分:-2)

尝试在.bat文件

的末尾添加新行