From d17acbf5151c923a3588c8dd8697041fc21cf9dd Mon Sep 17 00:00:00 2001 From: Can Ibanoglu Date: Fri, 8 Nov 2013 21:21:56 +0200 Subject: [PATCH 1/3] Added virtual environment enforcing for pip for the osx installation tutorial --- docs/starting/install/osx.rst | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/docs/starting/install/osx.rst b/docs/starting/install/osx.rst index dc6676733..b84eeb02f 100644 --- a/docs/starting/install/osx.rst +++ b/docs/starting/install/osx.rst @@ -119,6 +119,49 @@ An useful set of extensions to virtualenv is available in virtualenvwrapper, `RTFD `_ to find out more. +A note about Pip and Virtualenv +------------------------------- + +By now it should be clear that using virtual environments is a great way to keep +your development environment clean and keeping different projects' requirements +separate. + +When you start working on many different projects, it can be hard to remember to +activate the related virtual environment when you come back to a specific project. +As a result of this, it is very easy to install packages globally while thinking +that you are actually installing the package for the virtual environment of the +project. Over time this can result in a messy global package list. + +In order to make sure that you install packages to your active virtual environment +when you use ``pip install``, consider adding the following two lines to your +``~/.bashrc`` file: + +.. code-block:: console + export PIP_REQUIRE_VIRTUALENV=true + +After saving this change and sourcing the ``~/.bashrc`` file with ``source ~/.bashrc``, +pip will no longer let you install packages if you are not in a virtual environment. +If you try to use ``pip install`` outside of a virtual environment pip will +gently remind you that an activated virtual environment is needed to install +packages. + +.. code-block:: console + $ pip install requests + Could not find an activated virtualenv (required). + +You will of course need to install some packages globally and this can be accomplished +by adding the following to your ``~/.bashrc`` file: + +.. code-block:: console + gpip() { + PIP_REQUIRE_VIRTUALENV="" pip "$@" + } + +After saving the changes and sourcing your ``~/.bashrc`` file you can now install +packages globally by running ``gpip install``. You can change the name of the +function to anything you like, just keep in mind that you will have to use that +name when trying install packages globally with pip. + -------------------------------- This page is a remixed version of `another guide `_, From 100a4cb4228af1b7268f45906bdea0fe398e45b5 Mon Sep 17 00:00:00 2001 From: Can Ibanoglu Date: Thu, 6 Mar 2014 16:56:22 +0200 Subject: [PATCH 2/3] Created a new section for virtualenv and pip --- docs/starting/install/osx.rst | 44 ------------------------------ docs/starting/pip-virtualenv.rst | 46 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 44 deletions(-) create mode 100644 docs/starting/pip-virtualenv.rst diff --git a/docs/starting/install/osx.rst b/docs/starting/install/osx.rst index b84eeb02f..0489636f9 100644 --- a/docs/starting/install/osx.rst +++ b/docs/starting/install/osx.rst @@ -118,50 +118,6 @@ copy your code out of it, and then delete the main directory for the environment An useful set of extensions to virtualenv is available in virtualenvwrapper, `RTFD `_ to find out more. - -A note about Pip and Virtualenv -------------------------------- - -By now it should be clear that using virtual environments is a great way to keep -your development environment clean and keeping different projects' requirements -separate. - -When you start working on many different projects, it can be hard to remember to -activate the related virtual environment when you come back to a specific project. -As a result of this, it is very easy to install packages globally while thinking -that you are actually installing the package for the virtual environment of the -project. Over time this can result in a messy global package list. - -In order to make sure that you install packages to your active virtual environment -when you use ``pip install``, consider adding the following two lines to your -``~/.bashrc`` file: - -.. code-block:: console - export PIP_REQUIRE_VIRTUALENV=true - -After saving this change and sourcing the ``~/.bashrc`` file with ``source ~/.bashrc``, -pip will no longer let you install packages if you are not in a virtual environment. -If you try to use ``pip install`` outside of a virtual environment pip will -gently remind you that an activated virtual environment is needed to install -packages. - -.. code-block:: console - $ pip install requests - Could not find an activated virtualenv (required). - -You will of course need to install some packages globally and this can be accomplished -by adding the following to your ``~/.bashrc`` file: - -.. code-block:: console - gpip() { - PIP_REQUIRE_VIRTUALENV="" pip "$@" - } - -After saving the changes and sourcing your ``~/.bashrc`` file you can now install -packages globally by running ``gpip install``. You can change the name of the -function to anything you like, just keep in mind that you will have to use that -name when trying install packages globally with pip. - -------------------------------- This page is a remixed version of `another guide `_, diff --git a/docs/starting/pip-virtualenv.rst b/docs/starting/pip-virtualenv.rst new file mode 100644 index 000000000..56e33cceb --- /dev/null +++ b/docs/starting/pip-virtualenv.rst @@ -0,0 +1,46 @@ +.. _pip-virtualenv: + +Further Configuration of Pip and Virtualenv +------------------------------------------- + +By now it should be clear that using virtual envirtonments is a great way to keep +your development environment clean and keeping different projects' requirements +separate. + +When you start working on many different projects, it can be hard to remember to +activate the related virtual environment when you come back to a specific project. +As a result of this, it is very easy to install packages globally while thinking +that you are actually installing the package for the virtual environment of the +project. Over time this can result in a messy global package list. + +In order to make sure that you install packages to your active virtual environment +when you use ``pip install``, consider adding the following two lines to your +``~/.bashrc`` file: + +.. code-block:: console + export PIP_REQUIRE_VIRTUALENV=true + +After saving this change and sourcing the ``~/.bashrc`` file with ``source ~/.bashrc``, +pip will no longer let you install packages if you are not in a virtual environment. +If you try to use ``pip install`` outside of a virtual environment pip will gently +remind you that an activated virtual environment is needed to install packages. + +.. code-block:: console + $ pip install requests + Could not find an activated virtualenv (required). + +You will of course need to install some packages globally (usually ones that you +use across different projects consistenly) and this can be accomplished by adding +the following to your ``~/.bashrc`` file: + +.. code-block:: console + gpip() { + PIP_REQUIRE_VIRTUALENV="" pip "$@" + } + +After saving the changes and sourcing your ``~/.bashrc`` file you can now install +packages globally by running ``gpip install``. You can change the name of the +function to anything you like, just keep in mind that you will have to use that +name when trying to install packages globally with pip. + +----------------------------------------------------------- From 2f9fc823da8868b4c4aa152147eb80fc6abeb628 Mon Sep 17 00:00:00 2001 From: Can Ibanoglu Date: Sat, 15 Mar 2014 11:48:55 +0200 Subject: [PATCH 3/3] Deleted the horizontal line, took back the messed up commits --- docs/starting/pip-virtualenv.rst | 44 +++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/docs/starting/pip-virtualenv.rst b/docs/starting/pip-virtualenv.rst index 56e33cceb..c76623510 100644 --- a/docs/starting/pip-virtualenv.rst +++ b/docs/starting/pip-virtualenv.rst @@ -1,7 +1,10 @@ .. _pip-virtualenv: Further Configuration of Pip and Virtualenv -------------------------------------------- +=========================================== + +Requiring an active virtual environment for ``pip`` +--------------------------------------------------- By now it should be clear that using virtual envirtonments is a great way to keep your development environment clean and keeping different projects' requirements @@ -18,6 +21,7 @@ when you use ``pip install``, consider adding the following two lines to your ``~/.bashrc`` file: .. code-block:: console + export PIP_REQUIRE_VIRTUALENV=true After saving this change and sourcing the ``~/.bashrc`` file with ``source ~/.bashrc``, @@ -26,14 +30,50 @@ If you try to use ``pip install`` outside of a virtual environment pip will gent remind you that an activated virtual environment is needed to install packages. .. code-block:: console + $ pip install requests Could not find an activated virtualenv (required). +You can also do this configuration by editing your ``pip.conf`` or ``pip.ini`` +file. ``pip.conf`` is used by Unix and Mac OS X operating systems and it can be +found at: + +.. code-block:: console + + $HOME/.pip/pip.conf + +Similarly, the ``pip.ini`` file is used by Windows operating systems and it can +be found at: + +.. code-block:: console + + %HOME%\pip\pip.ini + +If you don't have a ``pip.conf`` or ``pip.ini`` file at these locations, you can +create a new file with the correct name for your operating system. + +If you already have a configuration file, just add the following line under the +``[global]`` settings to require an active virtual environment: + +.. code-block:: console + + require-virtualenv = true + +If you did not have a configuration file, you will need to create a new one and +add the following lines to this new file: + +.. code-block:: console + + [global] + require-virtualenv = true + + You will of course need to install some packages globally (usually ones that you use across different projects consistenly) and this can be accomplished by adding the following to your ``~/.bashrc`` file: .. code-block:: console + gpip() { PIP_REQUIRE_VIRTUALENV="" pip "$@" } @@ -42,5 +82,3 @@ After saving the changes and sourcing your ``~/.bashrc`` file you can now instal packages globally by running ``gpip install``. You can change the name of the function to anything you like, just keep in mind that you will have to use that name when trying to install packages globally with pip. - ------------------------------------------------------------