mirror of
https://github.com/kennethreitz/python-guide.git
synced 2026-06-05 23:00:18 +00:00
Wrap virtualenvs to 80 chars.
This commit is contained in:
+27
-14
@@ -1,15 +1,18 @@
|
||||
Virtual Environments
|
||||
====================
|
||||
|
||||
A Virtual Environment, put simply, is an isolated working copy of Python which allows you to work on a specific project without worry of affecting other projects.
|
||||
|
||||
For example, you can work on a project which requires Django 1.3 at the same time with a project which requires Django 1.0.
|
||||
A Virtual Environment, put simply, is an isolated working copy of Python which
|
||||
allows you to work on a specific project without worry of affecting other
|
||||
projects.
|
||||
|
||||
For example, you can work on a project which requires Django 1.3 while also
|
||||
maintaining a project which requires Django 1.0.
|
||||
|
||||
virtualenv
|
||||
----------
|
||||
|
||||
`virtualenv <http://pypi.python.org/pypi/virtualenv>`_ is a tool to create isolated Python environments.
|
||||
`virtualenv <http://pypi.python.org/pypi/virtualenv>`_ is a tool to create
|
||||
isolated Python environments.
|
||||
|
||||
Install it via pip::
|
||||
|
||||
@@ -22,28 +25,34 @@ Basic Usage
|
||||
|
||||
$ virtualenv ENVIRONMENT_NAME
|
||||
|
||||
This creates a copy of Python in whichever directory you ran the command in, placing it in a folder named ``ENVIRONMENT_NAME``.
|
||||
This creates a copy of Python in whichever directory you ran the command in,
|
||||
placing it in a folder named ``ENVIRONMENT_NAME``.
|
||||
|
||||
2. To begin using the virtual environment, it needs to be activated::
|
||||
|
||||
$ source ENVIRONMENT_NAME/bin/activate
|
||||
|
||||
You can then begin installing any new modules without affecting the system default Python or other virtual environments.
|
||||
You can then begin installing any new modules without affecting the system
|
||||
default Python or other virtual environments.
|
||||
|
||||
3. If you are done working in the virtual environment for the moment, you can deactivate it::
|
||||
3. If you are done working in the virtual environment for the moment, you can
|
||||
deactivate it::
|
||||
|
||||
$ deactivate
|
||||
|
||||
This puts you back to the system's default Python interpreter with all its installed libraries.
|
||||
This puts you back to the system's default Python interpreter with all its
|
||||
installed libraries.
|
||||
|
||||
To delete a virtual environment, just delete its folder.
|
||||
|
||||
virtualenvwrapper
|
||||
-----------------
|
||||
|
||||
`virtualenvwrapper <http://www.doughellmann.com/projects/virtualenvwrapper/>`_ provides a set of commands which makes working with virtual environments much more pleasant. It also places all your virtual environments into one place.
|
||||
`virtualenvwrapper <http://www.doughellmann.com/projects/virtualenvwrapper/>`_
|
||||
provides a set of commands which makes working with virtual environments much
|
||||
more pleasant. It also places all your virtual environments into one place.
|
||||
|
||||
To install (make sure virtualenv is already installed)::
|
||||
To install (make sure **virtualenv** is already installed)::
|
||||
|
||||
$ pip install virtualenvwrapper
|
||||
$ export WORKON_HOME=~/Envs
|
||||
@@ -64,8 +73,11 @@ This creates the ``ENVIRONMENT_NAME`` folder inside ``~/Envs``.
|
||||
|
||||
$ workon ENVIRONMENT_NAME
|
||||
|
||||
**virtualenvwrapper** provides tab-completion on environment names. It really helps when you have a lot of environments and have trouble remembering their names.
|
||||
``workon`` also deactivates whatever environment you are currently in, so you can quickly switch between environments.
|
||||
**virtualenvwrapper** provides tab-completion on environment names. It really
|
||||
helps when you have a lot of environments and have trouble remembering their
|
||||
names.
|
||||
``workon`` also deactivates whatever environment you are currently in, so you
|
||||
can quickly switch between environments.
|
||||
|
||||
3. Deactivating is still the same::
|
||||
|
||||
@@ -81,7 +93,8 @@ Other nifty commands include:
|
||||
List all of the environments.
|
||||
|
||||
``cdvirtualenv``
|
||||
Navigate into the directory of the currently activated virtual environment, so you can browse its ``site-packages``, for example.
|
||||
Navigate into the directory of the currently activated virtual environment,
|
||||
so you can browse its ``site-packages``, for example.
|
||||
|
||||
``cdsitepackages``
|
||||
Like the above, but directly into ``site-packages`` directory.
|
||||
@@ -89,4 +102,4 @@ Other nifty commands include:
|
||||
``lssitepackages``
|
||||
Shows contents of ``site-packages`` directory.
|
||||
|
||||
Full list of commands can be found `here <http://www.doughellmann.com/docs/virtualenvwrapper/command_ref.html#managing-environments>`_.
|
||||
A full list of commands can be found `here <http://www.doughellmann.com/docs/virtualenvwrapper/command_ref.html#managing-environments>`_.
|
||||
|
||||
Reference in New Issue
Block a user