Activate virtualenv via os.system()

前端 未结 4 775
一生所求
一生所求 2020-12-10 20:33

I\'m writing a Python-based shell script to boilerplate a Django app with virtualenv, pip, and fabric. Should be straightforward enough, but it appears that I\'m not able to

相关标签:
4条回答
  • 2020-12-10 20:52

    Just don't use "source activate" at all. It does nothing but alter your shell PATH to put the virtualenv's bin directory first. I presume your script knows the directory of the virtualenv it has just created; all you have to do is call _virtualenv_dir_/bin/easy_install by full path. Or _virtualenv_dir_/bin/python for running any other python script within the virtualenv.

    0 讨论(0)
  • 2020-12-10 20:53

    You could also install virtualenvwrapper, and use the postmkvirtualenv hook. I use it to automatically bring in fresh copies of pip and IPython into virtualenvs I create (as I don't want it using my system IPython). I also use it to copy pythonw into the virtualenv, otherwise wx-based stuff won't work. Looks like this:

    easy_install pip
    pip install -I ipython
    cd ~/bin
    python install_pythonw.py ${VIRTUAL_ENV}
    
    0 讨论(0)
  • 2020-12-10 20:59

    Each call to os.system runs the command in a new subshell, which has the same properties as the original python process.

    Try putting the commands into one string separated by semicolons.

    0 讨论(0)
  • 2020-12-10 21:00

    Each os.system call creates a new process. You'll need to ensure that the activate and the easy_install are run in the same os.system or subprocess call.

    0 讨论(0)
提交回复
热议问题