1

I'm wondering about running python script inside bat script. At first, I need to set up virtual environment which set up correctly. The last thing is to run python script. This is my bat file.

chdir C:\Projects\bob
start C:\Environments\venv\Scripts\activate
python C:\Projects\bob\main.py

Command does not starting the python script

python C:\Projects\bob\main.py
1
  • 1
    So what is your question? Doesn't it work? Commented Mar 20, 2020 at 19:58

1 Answer 1

3

The start command will run your activation script in a new terminal instance, so your venv will not be active for your next command. Use call instead:

chdir C:\Projects\bob
call C:\Environments\venv\Scripts\activate
python C:\Projects\bob\main.py

Alternatively you could forgo changing directories and calling activate all together, and just call the python executable in your venv directly

C:\Environments\venv\Scripts\python.exe C:\Projects\bob\main.py
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, don't bother with activating the virtual environment, in many cases it's not necessary, on the condition of course that you call explicitly the right python binary located inside the virtual environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.