X Tutup
The Wayback Machine - https://web.archive.org/web/20250625045358/https://github.com/python/cpython/pull/24003/files
Skip to content

bpo-22295: use python -m pip rather than plain pip in examples #24003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Doc/library/importlib.metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ something into it:

$ python3 -m venv example
$ source example/bin/activate
(example) $ pip install wheel
(example) $ python -m pip install wheel

You can get the version string for ``wheel`` by running the following:

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/itertools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ Substantially all of these recipes and many, many others can be installed from
the `more-itertools project <https://pypi.org/project/more-itertools/>`_ found
on the Python Package Index::

pip install more-itertools
python -m pip install more-itertools

The extended tools offer the same high performance as the underlying toolset.
The superior memory performance is kept by processing elements one at a time
Expand Down
24 changes: 12 additions & 12 deletions Doc/tutorial/venv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ package name followed by ``==`` and the version number:

If you re-run this command, ``pip`` will notice that the requested
version is already installed and do nothing. You can supply a
different version number to get that version, or you can run ``pip
install --upgrade`` to upgrade the package to the latest version:
different version number to get that version, or you can run ``python
-m pip install --upgrade`` to upgrade the package to the latest version:

.. code-block:: bash

Expand All @@ -143,14 +143,14 @@ install --upgrade`` to upgrade the package to the latest version:
Successfully uninstalled requests-2.6.0
Successfully installed requests-2.7.0

``pip uninstall`` followed by one or more package names will remove the
packages from the virtual environment.
``python -m pip uninstall`` followed by one or more package names will
remove the packages from the virtual environment.

``pip show`` will display information about a particular package:
``python -m pip show`` will display information about a particular package:

.. code-block:: bash

(tutorial-env) $ pip show requests
(tutorial-env) $ python -m pip show requests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The examples already in a virtual environment should not be changed because the whole point of the environment is to make sure the correct python and pip are being targeted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can revert those if that's what it takes to get this merged (please confirm), but would like to point out first that

  • they will then be the only places referring to the pip executable rather than python -m pip which might be a surprise to some readers, it gets more rare and there's no explanation for it, and
  • the point of using python -m pip instead of pip is just as valid in virtual envs as it is outside of them

---
Metadata-Version: 2.0
Name: requests
Expand All @@ -163,25 +163,25 @@ packages from the virtual environment.
Location: /Users/akuchling/envs/tutorial-env/lib/python3.4/site-packages
Requires:

``pip list`` will display all of the packages installed in the virtual
environment:
``python -m pip list`` will display all of the packages installed in
the virtual environment:

.. code-block:: bash

(tutorial-env) $ pip list
(tutorial-env) $ python -m pip list
novas (3.1.1.3)
numpy (1.9.2)
pip (7.0.3)
requests (2.7.0)
setuptools (16.0)

``pip freeze`` will produce a similar list of the installed packages,
but the output uses the format that ``pip install`` expects.
``python -m pip freeze`` will produce a similar list of the installed packages,
but the output uses the format that ``python -m pip install`` expects.
A common convention is to put this list in a ``requirements.txt`` file:

.. code-block:: bash

(tutorial-env) $ pip freeze > requirements.txt
(tutorial-env) $ python -m pip freeze > requirements.txt
(tutorial-env) $ cat requirements.txt
novas==3.1.1.3
numpy==1.9.2
Expand Down
X Tutup