Home > Blockchain >  Windows .bat file to run python script
Windows .bat file to run python script

Time:11-11

Try to create a Windows .bat file to achieve the below function:

cd C:\repo\demo
venv\Scripts\activate
python test.py

In Visual Studio Code terminal window, I can run the above lines without issue.

Created a .bat file as below:

cd C:\repo\demo
"C:\Users\jw\AppData\Local\Programs\Python\Python310\python.exe" "venv\Scripts\activate"
"C:\Users\jw\AppData\Local\Programs\Python\Python310\python.exe" "python heatmap.py"
pause

When double click the above .bat file to run it, end with error:

if [ "${BASH_SOURCE-}" = "$0" ]; then

SyntaxError: cannot assign to literal here. Maybe you meant '==' instead of '='?

How to correct the .bat file to make it work?

CodePudding user response:

I'm not too sure about the topic, but I found this online and it seems like it could be of use.

https://datatofish.com/batch-python-script/

Batch file to execute python script

CodePudding user response:

You should either remove "C:\...\python.exe" from the second line:

cd C:\repo\demo
"C:\Users\jw\AppData\Local\Programs\Python\Python310\python.exe" "venv\Scripts\activate"
python heatmap.py  <-- like this
pause

or remove python

cd C:\repo\demo
"C:\Users\jw\AppData\Local\Programs\Python\Python310\python.exe" "venv\Scripts\activate"
"C:\Users\jw\AppData\Local\Programs\Python\Python310\python.exe" "heatmap.py"
pause
  • Related