Launch urxvt with python venv

81 views Asked by At

So I am trying to create a script that launches a urxvt terminal and sourcing a venv/bin/activate python env at the same time like this:

virtualenv -p /usr/bin/python2.7 /tmp/venv;


urxvt -e sh -c "bash -c 'source /tmp/venv/bin/activate'; bash"

I cannot get it to work for some reason.

Does anyone know another way to achieve this?

2

There are 2 answers

0
phd On

The problem with the command

urxvt -e sh -c "bash -c 'source /tmp/venv/bin/activate'; bash"

is that the 1st bash sources activate script and then exits so the second bash doesn't start in the venv being activated. Run the second bash inside -c '…' with the venv activated:

urxvt -e sh -c "exec bash -c 'source /tmp/venv/bin/activate && exec bash'"

PS. I love to use exec to replace the current shell instead of making it fork and wait. Saves a few processor cycles and a few bytes of memory.

0
Sebastian Karlsson On

Solved it by changing it to this:

urxvt -e bash -c "source /tmp/venv/bin/activate; sh"

I am not sure why that works though.