Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8b2aa1f

Browse files
bsolomon1124brettcannon
authored andcommitted
Use python -m pip install in porting guide and venv docs (GH-13257)
This is to help prevent people from accidentally installing into the wrong Python interpreter if they are not aware of which Python interpreter `pip` points to.
1 parent a0d73a1 commit 8b2aa1f

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

Doc/howto/pyporting.rst

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,26 @@ are:
3131

3232
#. Only worry about supporting Python 2.7
3333
#. Make sure you have good test coverage (coverage.py_ can help;
34-
``pip install coverage``)
34+
``python -m pip install coverage``)
3535
#. Learn the differences between Python 2 & 3
36-
#. Use Futurize_ (or Modernize_) to update your code (e.g. ``pip install future``)
36+
#. Use Futurize_ (or Modernize_) to update your code (e.g. ``python -m pip install future``)
3737
#. Use Pylint_ to help make sure you don't regress on your Python 3 support
38-
(``pip install pylint``)
38+
(``python -m pip install pylint``)
3939
#. Use caniusepython3_ to find out which of your dependencies are blocking your
40-
use of Python 3 (``pip install caniusepython3``)
40+
use of Python 3 (``python -m pip install caniusepython3``)
4141
#. Once your dependencies are no longer blocking you, use continuous integration
4242
to make sure you stay compatible with Python 2 & 3 (tox_ can help test
43-
against multiple versions of Python; ``pip install tox``)
43+
against multiple versions of Python; ``python -m pip install tox``)
4444
#. Consider using optional static type checking to make sure your type usage
4545
works in both Python 2 & 3 (e.g. use mypy_ to check your typing under both
46-
Python 2 & Python 3).
46+
Python 2 & Python 3; ``python -m pip install mypy``).
4747

48+
.. note::
49+
50+
Note: Using ``python -m pip install`` guarantees that the ``pip`` you invoke
51+
is the one installed for the Python currently in use, whether it be
52+
a system-wide ``pip`` or one installed within a
53+
:ref:`virtual environment <tut-venv>`.
4854

4955
Details
5056
=======
@@ -71,7 +77,7 @@ Drop support for Python 2.6 and older
7177
While you can make Python 2.5 work with Python 3, it is **much** easier if you
7278
only have to work with Python 2.7. If dropping Python 2.5 is not an
7379
option then the six_ project can help you support Python 2.5 & 3 simultaneously
74-
(``pip install six``). Do realize, though, that nearly all the projects listed
80+
(``python -m pip install six``). Do realize, though, that nearly all the projects listed
7581
in this HOWTO will not be available to you.
7682

7783
If you are able to skip Python 2.5 and older, then the required changes

Doc/tutorial/venv.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ You can install the latest version of a package by specifying a package's name:
110110

111111
.. code-block:: bash
112112
113-
(tutorial-env) $ pip install novas
113+
(tutorial-env) $ python -m pip install novas
114114
Collecting novas
115115
Downloading novas-3.1.1.3.tar.gz (136kB)
116116
Installing collected packages: novas
@@ -122,7 +122,7 @@ package name followed by ``==`` and the version number:
122122

123123
.. code-block:: bash
124124
125-
(tutorial-env) $ pip install requests==2.6.0
125+
(tutorial-env) $ python -m pip install requests==2.6.0
126126
Collecting requests==2.6.0
127127
Using cached requests-2.6.0-py2.py3-none-any.whl
128128
Installing collected packages: requests
@@ -135,7 +135,7 @@ install --upgrade`` to upgrade the package to the latest version:
135135

136136
.. code-block:: bash
137137
138-
(tutorial-env) $ pip install --upgrade requests
138+
(tutorial-env) $ python -m pip install --upgrade requests
139139
Collecting requests
140140
Installing collected packages: requests
141141
Found existing installation: requests 2.6.0
@@ -193,7 +193,7 @@ necessary packages with ``install -r``:
193193

194194
.. code-block:: bash
195195
196-
(tutorial-env) $ pip install -r requirements.txt
196+
(tutorial-env) $ python -m pip install -r requirements.txt
197197
Collecting novas==3.1.1.3 (from -r requirements.txt (line 1))
198198
...
199199
Collecting numpy==1.9.2 (from -r requirements.txt (line 2))

0 commit comments

Comments
 (0)