Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start Python virtual environment in .bat batch file?

I need to set up a long list of temporary environment variables every time when I start a Python Flask app on Windows 10. Now I would like to create a batch file to run with all settings in one double click. The following lines run well if I copy them and paste to cmd prompt, but I couldn't run them in the batch file.

The execution of batch file always gets tripped and exited at the 2nd line venv\scripts\activate in the batch file, which has no issue at all if I copy and paste line by line at cmd.

cd C:\py\project
venv\scripts\activate

set env1=val1
set env2=val2
set FLASK_APP=some.py

flask run
like image 468
D Emma Avatar asked Dec 07 '22 12:12

D Emma


1 Answers

One of the many (far too many) quirks of .bat files is that if you launch another .bat file, it doesn't know where to return to.
You need to explicitly call it:

call venv\scripts\activate
like image 101
molbdnilo Avatar answered Dec 11 '22 11:12

molbdnilo