Reputation: 89
I've installed Anaconda 1.9.12 and everything works fine for designing python scripts and executing them. Now that I have my code ready, I want to allow for an external program to call python myCode.py myInputFile.dat
but this fails to activate the environment and my import commands fail. I can activate the environment manually by using the Activate.bat
file the Anaconda provides but when I put this into a batch file, the command prompt exists after I called Activate.bat
and never gets to python.exe
Here is my batch file
"C:\ProgramData\Anaconda3\condabin\activate.bat"
C:\ProgramData\Anaconda3\python.exe myCode.py myInputFile.dat
The first line runs and then the command window closes before it gets to the next line. I really want this thing to run automatically without me having to open a command window, activate the environment and then call the python routine.
Is there a way to do this?
Upvotes: 3
Views: 5958
Reputation: 76700
Not sure where the conda.exe
is on Windows, but one can use conda.exe run
to execute commands within environments without having to activate them in a shell session. For example, you should be able to do something like
C:\ProgramData\Anaconda3\Scripts\conda.exe run -n base python myCode.py myInputFile.dat
If you require interactivity, you’ll also need either (or both) the flags --live-stream
or --no-capture-output
.
Upvotes: 1