lets say i created a virtualenv called venv (virtualenv venv)
From reading tutorials, i read there are 2 ways to activate virtual env:
. venv/bin/activate
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!
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.
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.
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.
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With