This page looks best with JavaScript enabled

Activate python virtualenv programmatically

 ·   ·  β˜• 1 min read

    Putting the script into the bin of your virtualenv, and then adding that bin location to your global PATH will not automatically source your virtualenv. You do need to source it first to make it active.

    All that your system knows is to check that extra path for the executable and run it. There isn’t anything in that script indicating a virtualenv.

    You could, however, hardcode the she-bang line to your virtualenv python, in which case the site-packages will end up on the path:


    Or another option is to simply create a tiny bash wrapper that calls your original pythons script, which will allow you to leave your original script with a generic she-bang..

    So if is: #!/usr/bin/env python

    Then you can make a myscript :


    When you do myscript, it will explicitly call your python script with the interpreter you set up.

    activate_this = './venv/Scripts/'

    Ohidur Rahman Bappy
    Ohidur Rahman Bappy
    πŸ“šLearner 🐍 Developer