Skip to content

Commit 2f9fc82

Browse files
author
Can Ibanoglu
committed
Deleted the horizontal line, took back the messed up commits
1 parent 2c48b39 commit 2f9fc82

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

docs/starting/pip-virtualenv.rst

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
.. _pip-virtualenv:
22

33
Further Configuration of Pip and Virtualenv
4-
-------------------------------------------
4+
===========================================
5+
6+
Requiring an active virtual environment for ``pip``
7+
---------------------------------------------------
58

69
By now it should be clear that using virtual envirtonments is a great way to keep
710
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
1821
``~/.bashrc`` file:
1922

2023
.. code-block:: console
24+
2125
export PIP_REQUIRE_VIRTUALENV=true
2226
2327
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
2630
remind you that an activated virtual environment is needed to install packages.
2731

2832
.. code-block:: console
33+
2934
$ pip install requests
3035
Could not find an activated virtualenv (required).
3136
37+
You can also do this configuration by editing your ``pip.conf`` or ``pip.ini``
38+
file. ``pip.conf`` is used by Unix and Mac OS X operating systems and it can be
39+
found at:
40+
41+
.. code-block:: console
42+
43+
$HOME/.pip/pip.conf
44+
45+
Similarly, the ``pip.ini`` file is used by Windows operating systems and it can
46+
be found at:
47+
48+
.. code-block:: console
49+
50+
%HOME%\pip\pip.ini
51+
52+
If you don't have a ``pip.conf`` or ``pip.ini`` file at these locations, you can
53+
create a new file with the correct name for your operating system.
54+
55+
If you already have a configuration file, just add the following line under the
56+
``[global]`` settings to require an active virtual environment:
57+
58+
.. code-block:: console
59+
60+
require-virtualenv = true
61+
62+
If you did not have a configuration file, you will need to create a new one and
63+
add the following lines to this new file:
64+
65+
.. code-block:: console
66+
67+
[global]
68+
require-virtualenv = true
69+
70+
3271
You will of course need to install some packages globally (usually ones that you
3372
use across different projects consistenly) and this can be accomplished by adding
3473
the following to your ``~/.bashrc`` file:
3574

3675
.. code-block:: console
76+
3777
gpip() {
3878
PIP_REQUIRE_VIRTUALENV="" pip "$@"
3979
}
@@ -42,5 +82,3 @@ After saving the changes and sourcing your ``~/.bashrc`` file you can now instal
4282
packages globally by running ``gpip install``. You can change the name of the
4383
function to anything you like, just keep in mind that you will have to use that
4484
name when trying to install packages globally with pip.
45-
46-
-----------------------------------------------------------

0 commit comments

Comments
 (0)