I am trying to optimise my workflow and so I want to issue a command from a python program that will open a terminal, switch to a specific directory and then run a command, in this case activate a virtual environment.
This question is similar to this one. However, I am not sure how to handle the call to the virtualenv.
import subprocess
subprocess.run(['gnome-terminal', '--working-directory', '/home/jeff/projects', 'bash \"workon wagtail\" '])
What happens is that the new window get created in the correct directory but the workon does not get called
Working in the terminal, if I use
gnome-terminal --working-directory='/home/jeff/projects' -- bash -ci "source /usr/bin/virtualenvwrapper.sh && workon ; exec bash;"
The command works, but the workon is performed before the terminal prompt appears
If I run
gnome-terminal --working-directory='/home/jeff/projects' -- bash -ci "source /usr/bin/virtualenvwrapper.sh && workon wagtail; exec bash;"
the terminal does not enter the venv (wagtail). However the command
workon wagtail
is in the terminal history