Try to create a Windows .bat file to achieve the below function:
cd C:repodemo
venvScriptsactivate
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:repodemo
"C:UsersjwAppDataLocalProgramsPythonPython310python.exe" "venvScriptsactivate"
"C:UsersjwAppDataLocalProgramsPythonPython310python.exe" "python test.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 ‘=’?
Also tried the below .bat code, not working either:
cd C:repodemo
venvScriptsactivate
python test.py
pause
How to correct the .bat file to make it work?
======================================
Based on @Compo’s comment, tried the below version and it successfully executed python test.py
:
cd C:repodemo
call "venvScriptsactivate.bat"
python test.py
pause
but seems it didn’t finish call "venvScriptsactivate.bat"
, the command line window shows as below:
When manually run the code, it will prefix the path with (venv) as below which shows the proper result:
============================================
UPDATE:
The below .bat version works now, an answer from this question
cd C:repodemo && call "venvScriptsactivate.bat" && python test.py && pause
2
Answers
You should either remove "C:…python.exe" from the second line:
or remove python
Try this: