Sebastian Karlsson
Sebastian Karlsson

Reputation: 745

Launch urxvt with python venv

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?

Upvotes: 1

Views: 83

Answers (2)

phd
phd

Reputation: 94706

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.

Upvotes: 0

Sebastian Karlsson
Sebastian Karlsson

Reputation: 745

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.

Upvotes: 0

Related Questions