-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.bat
34 lines (25 loc) · 1.1 KB
/
run.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
@echo off
rem How to run a Python script in a given conda environment from a batch file.
rem It doesn't require:
rem - conda to be in the PATH
rem - cmd.exe to be initialized with conda init
rem Define here the path to your conda installation
set CONDAPATH=E:\Anaconda3\
rem Define here the name of the environment
set ENVNAME=hfc
rem The following command activates the base environment.
rem call C:\ProgramData\Miniconda3\Scripts\activate.bat C:\ProgramData\Miniconda3
if %ENVNAME%==base (set ENVPATH=%CONDAPATH%) else (set ENVPATH=%CONDAPATH%\envs\%ENVNAME%)
rem Activate the conda environment
rem Using call is required here, see: https://stackoverflow.com/questions/24678144/conda-environments-and-bat-files
call %CONDAPATH%\Scripts\activate.bat %ENVPATH%
rem Run a python script in that environment
python main.py
rem Deactivate the environment
call conda deactivate
rem If conda is directly available from the command line then the following code works.
rem call activate someenv
rem python script.py
rem conda deactivate
rem One could also use the conda run command
rem conda run -n someenv python script.py