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

后端 未结 3 1822
情歌与酒
情歌与酒 2020-12-13 09:05

I\'ve done a fair bit of bash scripting, but very little batch scripting on Windows. I\'m trying to activate a Python virtualenv, run a Python script, then deactivate the vi

3条回答
  •  星月不相逢
    2020-12-13 09:36

    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.

提交回复
热议问题