2

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
4

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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