Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my batch script stop after activating a new conda env?

This is enough to reproduce the issue:

Save as test.bat

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

Run from cmd.

>test.bat "testname"

Output:

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>

And that's it. The echo statement doesn't execute, but there is no error message.

Why does activating the conda env halt the batch script, and is there a way around it?

like image 563
Jamie Bull Avatar asked Mar 09 '17 10:03

Jamie Bull


People also ask

What happens when you activate a conda environment?

With conda, you can create, export, list, remove, and update environments that have different versions of Python and/or packages installed in them. Switching or moving between environments is called activating the environment. You can also share an environment file.

How do you activate an already created conda environment?

To activate your Conda environment, type source activate <yourenvironmentname> . Note that conda activate will not work on Discovery with this version. To install a specific package, type conda install -n <yourenvironmentname> [package] . To deactivate the current, active Conda environment, type conda deactivate .

What is the difference between conda activate and source activate?

Generally, you won't find too much of a difference between conda activate and the old source activate , except that it's meant to be faster, and work the same across different operating systems (the latter difference makes conda activate a huge improvement IMO).

Do batch files always start with @echo off?

In a batch file, the @ symbol at the start of a line is the same as ECHO OFF applied to the current line only.


1 Answers

use

call activate %name%
  • I'm assuming that activate is a batch file. If you call it, processing will return after that batch is finished. Without the call, execution is transferred to activate and ends when activate ends.
like image 85
Magoo Avatar answered Sep 29 '22 04:09

Magoo