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

前端 未结 2 451
日久生厌
日久生厌 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 02:58

    The source or . command causes the current shell to execute the given source file in it's environment. You'll need a shell in order to use it. This probably isn't as clean as you'd like it, since it uses a string instead of a list to represent the command, but it should work.

    import subprocess
    
    subprocess.check_call( [ 'virtualenv', 'env-dir' ] )
    
    subprocess.check_call(
        ' . env-dir/bin/activate && pip install python-dateutil ',
        shell = True
    )
    

提交回复
热议问题