1
1
Virtual Environment
2
2
-------------------
3
3
4
- Have you ever heard of ``virtualenv ``? The chances are that if you are a
5
- beginner then you might not have heard about it but if you are a
6
- seasoned programmer than it's a vital part of your toolset. So what
7
- ``virtualenv `` really is? ``Virtualenv `` is a tool which allows us to
4
+ Have you ever heard of ``virtualenv ``? If you are a beginner,
5
+ then you might not have heard about it but if you are a
6
+ seasoned programmer then it may well be a vital part of your toolset.
7
+
8
+ So what is ``virtualenv ``? ``Virtualenv `` is a tool which allows us to
8
9
make isolated python environments. Imagine you have an application that
9
- needs version 2 of a LibraryBar , but another application requires
10
+ needs version 2 of a library , but another application requires
10
11
version 3. How can you use and develop both these applications?
11
12
12
13
If you install everything into ``/usr/lib/python2.7/site-packages `` (or
13
14
whatever your platform's standard location is), it's easy to end up in a
14
- situation where you unintentionally upgrade a package that shouldn't be
15
- upgraded. In another case just imagine that you have an application
16
- which is fully developed and you do not want to make any change to the
17
- libraries it is using but at the same time you start developing another
18
- application which requires the updated versions of those libraries. What
19
- will you do? It is where ``virtualenv `` comes into play. It creates
20
- isolated environments for your python application and allows you to
21
- install Python libraries in that isolated environment instead of
22
- installing them globally.
23
-
24
- In order to install it just type this command in the shell:
15
+ situation where you unintentionally upgrade a package.
16
+
17
+ In another case, imagine that you have an application which is fully
18
+ developed and you do not want to make any change to the libraries it is
19
+ using but at the same time you start developing another application
20
+ which requires the updated versions of those libraries.
21
+
22
+ What will you do? Use ``virtualenv ``! It creates isolated environments
23
+ for your python application and allows you to install Python libraries
24
+ in that isolated environment instead of installing them globally.
25
+
26
+ To install it, just type this command in the shell:
25
27
26
28
.. code :: python
27
29
28
30
$ pip install virtualenv
29
31
30
- Now i am going to list some of it's commands. The most important ones
31
- are:
32
+ The most important commands are:
32
33
33
34
- ``$ virtualenv myproject ``
34
35
- ``$ source bin/activate ``
35
36
36
37
This first one makes an isolated virtualenv environment in the
37
38
``myproject `` folder and the second command activates that isolated
38
- environment. While running the first command you have to make a
39
- decision.
39
+ environment.
40
+
41
+ While creating the virtualenv you have to make a decision. Do you
42
+ want this virtualenv to use packages from your system ``site-packages ``
43
+ or install them in the virtualenv’s site-packages? By default,
44
+ virtualenv will not give access to the global ``site-packages ``.
40
45
41
- Do you want this virtualenv to use packages from your system
42
- ``site-packages `` or install them in the virtualenv’s site-packages? By
43
- default, virtualenv will not give access to the global ``site-packages ``.
44
46
If you want your ``virtualenv `` to have access to your systems
45
- ``site-packages `` use the ``--system-site-packages `` switch when creating
47
+ ``site-packages ``, use the ``--system-site-packages `` switch when creating
46
48
your virtualenv like this:
47
49
48
50
.. code :: python
@@ -55,6 +57,9 @@ You can turn off the ``env`` by typing:
55
57
56
58
$ deactivate
57
59
60
+ Running `python ` after deactivating will use your system installation
61
+ of Python again.
62
+
58
63
**Bonus **
59
64
60
65
You can use ``smartcd `` which is a library for bash and zsh and allows
@@ -63,7 +68,6 @@ helpful to activate and deactivate a ``virtualenv`` when you change
63
68
directories. I have used it quite a lot and love it. You can read more
64
69
about it on `GitHub <https://github.com/cxreg/smartcd >`__
65
70
66
- This was just a short intro to virtualenv. There's a lot more to it. For
67
- further study i recommend `this
68
- link. <http://docs.python-guide.org/en/latest/dev/virtualenvs/> `__
69
- It will remove all of your confusions about virtualenv.
71
+ This was just a short intro to virtualenv. There's a lot more to it; `this
72
+ link <http://docs.python-guide.org/en/latest/dev/virtualenvs/> `__ has more
73
+ information.
0 commit comments