From f29b0284b92efb7e9fa27f80fc707fce948cf231 Mon Sep 17 00:00:00 2001 From: John Del Rosario Date: Sun, 1 Jan 2012 23:36:22 +0800 Subject: [PATCH 1/3] Flesh out virtualenvs section. --- docs/dev/virtualenvs.rst | 83 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 3 deletions(-) diff --git a/docs/dev/virtualenvs.rst b/docs/dev/virtualenvs.rst index 385fe9497..cf960077d 100644 --- a/docs/dev/virtualenvs.rst +++ b/docs/dev/virtualenvs.rst @@ -1,15 +1,92 @@ Virtual Environments ==================== -.. todo:: Explain "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. + virtualenv ---------- -.. todo:: Write about virtualenv +`virtualenv `_ is a tool to create isolated Python environments. + +Install it via pip:: + + $ pip install virtualenv + +Basic Usage +~~~~~~~~~~~ + +1. Create a virtual environment:: + + $ 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``. + +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. + +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. + +To delete a virtual environment, just delete its folder. virtualenvwrapper ----------------- -.. todo:: Write about virtualenvwrapper +`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):: + + $ pip install virtualenvwrapper + $ export WORKON_HOME=~/Envs + $ source /usr/local/bin/virtualenvwrapper.sh + +(Full instructions `here `_.) + +Basic Usage +~~~~~~~~~~~ + +1. Create a virtual environment:: + + $ mkvirtualenv ENVIRONMENT_NAME + +This creates the ``ENVIRONMENT_NAME`` folder inside ``~/Envs``. + +2. Work on a virtual environment:: + + $ 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. + +3. Deactivating is still the same:: + + $ deactivate + +4. To delete:: + + $ rmvirtualenv ENVIRONMENT_NAME + +Other nifty commands include: + +``lsvirtualenv`` + 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. + +``cdsitepackages`` + Like the above, but directly into ``site-packages`` directory. + +``lssitepackages`` + Shows contents of ``site-packages`` directory. +Full list of commands can be found `here `_. From 291ab64150212b26b004ac0f4a0cae8eac2524ff Mon Sep 17 00:00:00 2001 From: John Louis Del Rosario Date: Mon, 2 Jan 2012 22:48:37 +0800 Subject: [PATCH 2/3] Wrap virtualenvs to 80 chars. --- docs/dev/virtualenvs.rst | 41 ++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/docs/dev/virtualenvs.rst b/docs/dev/virtualenvs.rst index cf960077d..942406ead 100644 --- a/docs/dev/virtualenvs.rst +++ b/docs/dev/virtualenvs.rst @@ -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 `_ is a tool to create isolated Python environments. +`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 `_ 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 `_ +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 `_. +A full list of commands can be found `here `_. From 7e3b364d0ff7971f62adbc160e93ea0410205a96 Mon Sep 17 00:00:00 2001 From: John Del Rosario Date: Thu, 5 Jan 2012 15:06:24 +0800 Subject: [PATCH 3/3] Make virtualenvs conform to the style guide a bit more. Plus some additional changes --- docs/dev/virtualenvs.rst | 63 +++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/docs/dev/virtualenvs.rst b/docs/dev/virtualenvs.rst index 942406ead..9def09bfe 100644 --- a/docs/dev/virtualenvs.rst +++ b/docs/dev/virtualenvs.rst @@ -14,29 +14,37 @@ virtualenv `virtualenv `_ is a tool to create isolated Python environments. -Install it via pip:: +Install it via pip: + +.. code-block:: console $ pip install virtualenv Basic Usage ~~~~~~~~~~~ -1. Create a virtual environment:: +1. Create a virtual environment: + +.. code-block:: console - $ virtualenv ENVIRONMENT_NAME + $ virtualenv venv This creates a copy of Python in whichever directory you ran the command in, -placing it in a folder named ``ENVIRONMENT_NAME``. +placing it in a folder named ``venv``. + +2. To begin using the virtual environment, it needs to be activated: -2. To begin using the virtual environment, it needs to be activated:: +.. code-block:: console - $ source ENVIRONMENT_NAME/bin/activate + $ source venv/bin/activate 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:: + deactivate it: + +.. code-block:: console $ deactivate @@ -45,33 +53,43 @@ installed libraries. To delete a virtual environment, just delete its folder. +After a while, though, you might end up with a lot of virtual environments +littered across your system, and its possible you'll forget their names or +where they were placed. + virtualenvwrapper ----------------- `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. +more pleasant. It also places all your virtual environments in one place. -To install (make sure **virtualenv** is already installed):: +To install (make sure **virtualenv** is already installed): + +.. code-block:: console $ pip install virtualenvwrapper $ export WORKON_HOME=~/Envs $ source /usr/local/bin/virtualenvwrapper.sh -(Full instructions `here `_.) +(`Full virtualenvwrapper install instructions `_.) Basic Usage ~~~~~~~~~~~ -1. Create a virtual environment:: +1. Create a virtual environment: + +.. code-block:: console + + $ mkvirtualenv venv - $ mkvirtualenv ENVIRONMENT_NAME +This creates the ``venv`` folder inside ``~/Envs``. -This creates the ``ENVIRONMENT_NAME`` folder inside ``~/Envs``. +2. Work on a virtual environment: -2. Work on a virtual environment:: +.. code-block:: console - $ workon ENVIRONMENT_NAME + $ workon venv **virtualenvwrapper** provides tab-completion on environment names. It really helps when you have a lot of environments and have trouble remembering their @@ -79,15 +97,20 @@ names. ``workon`` also deactivates whatever environment you are currently in, so you can quickly switch between environments. -3. Deactivating is still the same:: +3. Deactivating is still the same: + +.. code-block:: console $ deactivate -4. To delete:: +4. To delete: + +.. code-block:: console - $ rmvirtualenv ENVIRONMENT_NAME + $ rmvirtualenv venv -Other nifty commands include: +Other useful commands +~~~~~~~~~~~~~~~~~~~~~ ``lsvirtualenv`` List all of the environments. @@ -102,4 +125,4 @@ Other nifty commands include: ``lssitepackages`` Shows contents of ``site-packages`` directory. -A full list of commands can be found `here `_. +`Full list of virtualenvwrapper commands `_.