virtualenvwrapper functions unavailable in shell scripts

前端 未结 8 825
夕颜
夕颜 2020-12-01 03:44

So, once again, I make a nice python program which makes my life ever the more easier and saves a lot of time. Ofcourse, this involves a virtualenv, made with the mkvi

8条回答
  •  一个人的身影
    2020-12-01 03:44

    Just source the virtualenvwrapper.sh script in your script to import the virtualenvwrapper's functions. You should then be able to use the workon function in your script.

    And maybe better, you could create a shell script (you could name it venv-run.sh for example) to run any Python script into a given virtualenv, and place it in /usr/bin, /usr/local/bin, or any directory which is in your PATH.

    Such a script could look like this:

    #!/bin/sh
    # if virtualenvwrapper.sh is in your PATH (i.e. installed with pip)
    source `which virtualenvwrapper.sh`
    #source /path/to/virtualenvwrapper.sh # if it's not in your PATH
    workon $1
    python $2
    deactivate
    

    And could be used simply like venv-run.sh my_virtualenv /path/to/script.py

提交回复
热议问题