@@ -97,6 +97,87 @@ virtualenv
9797Virtualenv is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them.
9898It solves the "Project X depends on version 1.x but, Project Y needs 4.x" dilemma and keeps your global site-packages directory clean and manageable.
9999
100+ `virtualenv <http://www.virtualenv.org/en/latest/index.html >`_ creates
101+ a folder which contains all the necessary executables to contain the
102+ packages that a Python project would need. An example workflow:
103+
104+ Install virtualenv:
105+
106+ ::
107+
108+ $ pip install virtualenv
109+
110+ or, depending on what's available:
111+
112+ ::
113+
114+ $ easy_install virtualenv
115+
116+ Create a virtual environment for a project:
117+
118+ ::
119+
120+ $ cd my_project
121+ $ virtualenv venv
122+
123+ ``virtualenv venv `` will create a folder in the currect directory
124+ which will contain the Python executable files, and a copy of the ``pip ``
125+ library which you can use to install other packages. The name of the
126+ virtual environment (in this case, it was ``venv ``) can be anything;
127+ omitting the name will place the files in the current directory instead.
128+
129+ In order the start using the virtual environment, run
130+
131+ ::
132+
133+ $ source venv/bin/activate
134+
135+ or
136+
137+ ::
138+
139+ $ . venv/bin/activate
140+
141+ The name of the current virtual environment will now appear on the left
142+ of the prompt (e.g. ``(venv)Your-Computer:your_project UserName$ ``) to
143+ let you know that it's active. From now on, any package that you install
144+ using ``pip `` will be placed in the venv folder, isolated from the global
145+ Python installation.
146+
147+ To stop using an environment simply type ``deactivate ``. To remove the
148+ environment, just remove the directory it was installed into. (In this
149+ case, it would be ``rm -rf venv ``.
150+
151+ Other Notes
152+ ~~~~~~~~~~~
153+
154+ Running ``virtualenv `` with the option ``--no-site-packages `` will not
155+ include the packages that are installed globally. This can be useful
156+ for keeping the package list clean in case it needs to be accessed later.
157+
158+ In order to keep your environment consistent, it's a good idea to "freeze"
159+ the current state of the environment packages. To do this, run
160+
161+ ::
162+
163+ pip freeze > requirements.txt
164+
165+ This will create a ``requirements.txt `` file, which contains a simple
166+ list of all the packages in the current environment, and their respective
167+ versions. Later, when a different developer (or you, if you need to re-
168+ create the environment) can install the same packages, with the same
169+ versions by running
170+
171+ ::
172+
173+ pip install -r requirements.txt
174+
175+ This can help ensure consistency across installations, across deployments,
176+ and across developers.
177+
178+ Lastly, remember to exclude the virtual environment folder from source
179+ control by adding it to the ignore list.
180+
100181virtualenvwrapper
101182-----------------
102183
0 commit comments