I am having difficulties running a series of sequential commands using the subprocess module, i need to do this so a python program can call in an installation of a cv virtualenv and then run another python program (that needs to be run within the virtualenv)
This is the command string i run from terminal, you can see it contains multiple commands that run in sequence until the creation of the cv virtual env:
sudo pip install virtualenv virtualenvwrapper && sudo rm -rf ~/.cache/pip && export WORKON_HOME=$HOME/.virtualenvs && source /usr/local/bin/virtualenvwrapper.sh && source ~/.bashrc && mkvirtualenv cv Running this in the terminal returns me something like this:
(cv) name@computer:~$ from that i can run my python scripts that need the openCV
my code so far is this:
from subprocess import Popen, PIPE, STDOUT cmd1 = 'sudo pip install virtualenv virtualenvwrapper' cmd2 = 'sudo rm -rf ~/.cache/pip' cmd3 = 'export WORKON_HOME=$HOME/.virtualenvs' cmd4 = 'source /usr/local/bin/virtualenvwrapper.sh' cmd5 = 'source ~/.bashrc' cmd6 = 'mkvirtualenv cv' cmd7 = 'cd /script path' cmd8 = 'python novo.py' final = Popen("{}; {}; {}; {}; {}; {}; {}; {}".format(cmd1, cmd2,cmd3, cmd4, cmd5, cmd6, cmd7, cmd8), shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) stdout, nothing = final.communicate() log = open('log', 'w') log.write(stdout) log.close() And the errors in log look like this:
/bin/sh: 1: source: not found /bin/sh: 1: source: not found /bin/sh: 1: mkvirtualenv: not found How can i achieve a terminal like execution ? again, sequence is crucial.