Batch equivalent of “source” on Windows: how to run a Python script from a virtualenv

I’d say you just need to prepend ‘call’ to your activate.bat invocation, to ensure that the current batch file is resumed after activate is executed:

call %~dp0env\Scripts\activate.bat

Consider doing the same for deactivate.bat. Furthermore, if you want to ensure that the current cmd.exe environment is not polluted by a call to your batch file, consider wrapping your commands in a setlocal/endlocal command pair.

Leave a Comment