How to activate virtualenv in Linux? – Dev

The best answers to the question “How to activate virtualenv in Linux?” in the category Dev.

QUESTION:

I have been searching and tried various alternatives without success and spent several days on it now – driving me mad.

Running on Red Hat Linux with Python 2.5.2
Began using most recent Virtualenv but could not activate it, I found somewhere suggesting needed earlier version so I have used Virtualenv 1.6.4 as that should work with Python 2.6.

It seems to install the virtual environment ok

[[email protected] ~]$ python virtualenv-1.6.4/virtualenv.py virtual
New python executable in virtual/bin/python
Installing setuptools............done.
Installing pip...............done.

Environment looks ok

[[email protected] ~]$ cd virtual
[[email protected] ~/virtual]$ dir
bin  include  lib

Trying to activate

[[email protected] ~/virtual]$ . bin/activate
/bin/.: Permission denied.

Checked chmod

[[email protected] ~/virtual]$ cd bin
[[email protected] bin]$ ls -l
total 3160
-rw-r--r--    1 necrailk biz12        2130 Jan 30 11:38 activate
-rw-r--r--    1 necrailk biz12        1050 Jan 30 11:38 activate.csh
-rw-r--r--    1 necrailk biz12        2869 Jan 30 11:38 activate.fish
-rw-r--r-

Problem, so I changed it

[[email protected] bin]$ ls -l
total 3160
-rwxr--r--    1 necrailk biz12        2130 Jan 30 11:38 activate
-rw-r--r--    1 necrailk biz12        1050 Jan 30 11:38 activate.csh
-rw-r--r--    1 necrailk biz12        2869 Jan 30 11:38 activate.fish
-rw-r--r--    1 necrailk biz12        1005 Jan 30 11:38 activate_this.py
-rwxr-xr-x    1 necrailk biz

Try activate again

[[email protected] ~/virtual]$ . bin/activate
/bin/.: Permission denied.

Still no joy…

ANSWER:

You forgot to do source bin/activate where source is a executable name.
Struck me first few times as well, easy to think that manual is telling “execute this from root of the environment folder”.

No need to make activate executable via chmod.

ANSWER:

Here is my workflow after creating a folder and cd‘ing into it:

$ virtualenv venv --distribute
New python executable in venv/bin/python
Installing distribute.........done.
Installing pip................done.
$ source venv/bin/activate
(venv)$ python

ANSWER:

Go to the project directory. In my case microblog is the flask project directory and under microblog directory there should be app and venv folders. then run the below command, This is one worked for me in Ubuntu.

source venv/bin/activate

enter image description here

ANSWER:

You can do

source ./python_env/bin/activate

or just go to the directory

cd /python_env/bin/

and then

source ./activate

Good Luck.