Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am trying to wrap the following call into a script, which runs my Python virtual environment:

[lucas@lucas-ThinkPad-W520]/home/lucas/bin$ source /home/lucas/Dropbox/projects/competitive-programming/kaggle/venv/ipython-notebook/bin/activate                                
(ipython-notebook) [lucas@lucas-ThinkPad-W520]/home/lucas/bin$ deactivate
[lucas@lucas-ThinkPad-W520]/home/lucas/bin$ 

So, I created and ran the following bash script:

[lucas@lucas-ThinkPad-W520]/home/lucas/bin$ cat venv_python3.sh 
#!/bin/bash
#  /usr/bin/env bash
echo "starting python3 venv"
source /home/lucas/Dropbox/projects/competitiveprogramming/kaggle/venv/ipythonnotebook/bin/activate
[lucas@lucas-ThinkPad-W520]/home/lucas/bin$ venv_python3.sh 
starting python3 venv                                                                            
[lucas@lucas-ThinkPad-W520]/home/lucas/bin$ 

As you can see, it executes the echo call, but does not start my virtual environment. Am I missing something?

I've looked over several tutorials, but cannot find what is missing. Also, my /home/lucas/bin/, the location of my script, is in my $PATH.

Here are the file's permissions:

[lucas@lucas-ThinkPad-W520]/home/lucas/bin$ ls -la
total 52
drwxr-xr-x  3 lucas lucas 4096 Jun 28 23:14 .
drwxr-xr-x 79 lucas lucas 4096 Jun 28 23:13 ..
-rwxrw-r--  1 lucas lucas  164 Jun 28 23:13 venv_python3.sh
share|improve this question

1 Answer 1

At the top of the activate script it says you have to source it and that you cannot run it directly. What it does, is changing some things in the session of bash into which the file is sourced.

In your case that bash is the bash that is invoked by running the venv_python3.sh script, not the bash you are typing into interactively.

What you could do is make a bash function (or an alias) that does the sourcing for you, then the 'sourcing' would happen to your interactive bash.

However I recommend you look at virtualenvwrapper, which makes working with multiple virtualenvs much more easy and might solve the 'problem' for which you created this script in the first place.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.