Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Virtualenv ". venv/bin/activate" vs "source venv/bin/activate"

lets say i created a virtualenv called venv (virtualenv venv)

From reading tutorials, i read there are 2 ways to activate virtual env:

  1. . venv/bin/activate

  2. source venv/bin/activate

I think they both accomplish the same thing, but i dont understand whats going on.

Also for number 1, doesnt the "." just mean the current folder? but it doesnt work if i just type in "venv/bin/activate" without the "."

any help would be great!

like image 729
anc1revv Avatar asked Jun 14 '12 06:06

anc1revv


People also ask

What does VENV bin activate do?

Activate the virtual environment Activation makes the virtual environment the default Python interpreter for the duration of a shell session. You'll need to use different syntax for activating the virtual environment depending on which operating system and command shell you're using.

Do I need to activate VENV?

Activating the virtualenv gives you convenience. It is never required. Activating makes the PATH update stick until you deactivate again, and that can be convenient.

What is the difference between VENV and virtualenv?

These are almost completely interchangeable, the difference being that virtualenv supports older python versions and has a few more minor unique features, while venv is in the standard library.


1 Answers

. and source do exactly the same thing, with the only difference being that while source is more readable, it may not be available in all shells.

The command runs the contents of the script within the current shell, and this is important in the case of activate, because one of the things that the script does is exports and modifies environment variables within your current shell.

If you were to run it using ./path/to/activate, the script will be run within a subshell and all environment variables that are set will be lost once the script completes and the subshell terminates.

Also for number 1, doesn't the "." just mean the current folder?

. has a different meaning depending on the context. It only means "current folder" when used as (or part of) a path.

From http://en.wikipedia.org/wiki/Dot_%28Unix%29:

The dot command is not to be confused with a dot file, which is a dot-prefixed hidden file or hidden directory.


As an aside, I would suggest that you take a look at virtualenvwrapper which provides additional wrapper commands that make virtualenv much easier to use.

Using virtualenvwrapper, switching to an evironment is done simply by calling:

workon YOUR_ENV
like image 114
Shawn Chin Avatar answered Sep 30 '22 19:09

Shawn Chin