简体   繁体   中英

Run windows batch file to call on python scripts with my anaconda environment

I have anaconda installed and wanted to call on my python scripts through the Windows Batch File ('.bat' extension). However, when I run my batch file, it says that the windows command prompt doesn't recognize python. So then, I add "conda activate" onto the batch file and it completely messes up my anaconda environment installed on my laptop.

I understand that anaconda installs a separate environment for running python onto my laptop so should I just install the normal python.exe to run this batch file or can I find ways to activate my anaconda base onto command prompt?

Pop up an anaconda prompt Type path It will say something like

PATH=C:\ProgramData\Anaconda3;C:\ProgramData\Anaconda3\Library\mingw-w64\bin;C:\ProgramData\Anaconda3\Library\usr\bin;C:\ProgramData\Anaconda3\Library\bin;C:\ProgramData\Anaconda3\Scripts;C:\ProgramData\Anaconda3\bin;C:\ProgramData\Anaconda3\condabin;C:\WINDOWS\system32;...

Copy from C:\ to C:\Windows\system32. Paste it at point XXX in your batch file

The batch file

setlocal
path XXX;%path%
python script.py
endlocal
echo "Booting application.."
conda init
conda activate YOUR_ENV
python script.py
read -p "Press [Enter] key to close window..."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM