Can I use a single python script to create a virtualenv and install requirements.txt?

前端 未结 2 438
日久生厌
日久生厌 2021-01-07 02:38

I am trying to create a script where i create a virtualenv if it has not been made, and then install requirements.txt in it.

I can\'t call the normal source /env/bin

2条回答
  •  不知归路
    2021-01-07 03:06

    source is a shell builtin command, not a program. It cannot and shouldn't be executed with subprocess. You can activate your fresh virtual env by executing activate_this.py in the current process:

    if not os.path.exists(env_path):
        call(['virtualenv', env_path])
        activate_this = os.path.join(env_path, 'bin', 'activate_this.py')
        execfile(activate_this, dict(__file__=activate_this))
    
    else:
        print "INFO: %s exists." %(env_path)
    

提交回复
热议问题