Article 5QW2H bash - can't setup virtualenv (and cd) from script?

bash - can't setup virtualenv (and cd) from script?

by
scottmusician
from LinuxQuestions.org on (#5QW2H)
Hi all,

I'm trying to create a little bash script that:

(a) switches to a directory (~/myapp)
(b) creates a python virtualenv (eg. myapp-env)
(c) activates the virtualenv , so that my shell is ready to start operating in this new, isolated virtual python environment.

I've a neat bash one-liner that does this, and works fine when just punched into the command line:

Quote:
cd /home/me/myapp;mkvirtualenv myapp-env;workon myapp-env
but I can't seem to add this into any scripts - presumably because the script executes in a separate child process that doesn't inherit my local (~/.bashrc) stuff?

How can I convert this to a script? Alternatively, I'd be happy to convert the above one-liner to a variable, and execute that (I'm quite new to bash so I'm not even sure how to do that! But I could work it out relatively easily, I think).

Thanks for your help!latest?d=yIl2AUoC8zA latest?i=_ZFoxFYT81Y:GjZmGzlwtgw:F7zBnMy latest?i=_ZFoxFYT81Y:GjZmGzlwtgw:V_sGLiP latest?d=qj6IDK7rITs latest?i=_ZFoxFYT81Y:GjZmGzlwtgw:gIN9vFw_ZFoxFYT81Y
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments