Skip to content

Commit 1e5db9e

Browse files
Chad Smiththeacodes
authored andcommitted
add instructions to install python CLI applications with pipx (#594)
* add instructions to install python CLI applications with pipx * create new guide for Installing stand alone command line tools (#406) * add pipx to key projects; update pipx url; update installation instructions; document pipx list * update pipx url in key projects * clarify PATH text; fix upgrade command * remove mention of symlinks
1 parent 7edc10d commit 1e5db9e

4 files changed

Lines changed: 129 additions & 3 deletions

File tree

source/guides/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ introduction to packaging, see :doc:`/tutorials/index`.
1010

1111
tool-recommendations
1212
installing-using-pip-and-virtualenv
13+
installing-stand-alone-command-line-tools
1314
installing-using-linux-tools
1415
installing-scientific-packages
1516
multi-version-installs
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
Installing stand alone command line tools
2+
=========================================
3+
4+
Many packages have command line entry points. Examples of this type of application are
5+
`mypy <https://github.com/python/mypy>`_,
6+
`flake8 <https://github.com/PyCQA/flake8>`_,
7+
`pipenv <https://github.com/pypa/pipenv>`_,and
8+
`black <https://github.com/ambv/black>`_.
9+
10+
Usually you want to be able to access these from anywhere,
11+
but installing packages and their dependencies to the same global environment
12+
can cause version conflicts and break dependencies the operating system has
13+
on Python packages.
14+
15+
`pipx <https://github.com/pipxproject/pipx>`_ solves this by creating a virtual
16+
environment for each package, while also ensuring that package's applications
17+
are accessible through a directory that is on your ``$PATH``. This allows each
18+
package to be upgraded or uninstalled without causing conflicts with other
19+
packages, and allows you to safely run the program from anywhere.
20+
21+
.. Note:: pipx only works with Python 3.6+.
22+
23+
``pipx`` is installed with ``pip``:
24+
25+
::
26+
27+
$ pip install --user pipx
28+
$ pipx ensurepath # ensures the path of the CLI application directory is on your $PATH
29+
30+
.. Note:: You may need to restart your terminal for the path updates to take effect.
31+
32+
Now you can install packages with ``pipx install`` and access the package's entry point(s) from anywhere.
33+
34+
::
35+
36+
$ pipx install PACKAGE
37+
$ ENTRYPOINT_OF_PACKAGE [ARGS]
38+
39+
For example
40+
41+
::
42+
43+
$ pipx install cowsay
44+
installed package cowsay 2.0, Python 3.6.2+
45+
These binaries are now globally available
46+
- cowsay
47+
done! ✨ 🌟 ✨
48+
$ cowsay moo
49+
___
50+
< moo >
51+
===
52+
\
53+
\
54+
^__^
55+
(oo)\_______
56+
(__)\ )\/ ||----w |
57+
|| ||
58+
59+
To see a list of packages installed with pipx and which CLI applications are available, use ``pipx list``.
60+
61+
::
62+
63+
$ pipx list
64+
venvs are in /Users/user/.local/pipx/venvs
65+
symlinks to binaries are in /Users/user/.local/bin
66+
package black 18.9b0, Python 3.6.2+
67+
- black
68+
- blackd
69+
package cowsay 2.0, Python 3.6.2+
70+
- cowsay
71+
package mypy 0.660, Python 3.6.2+
72+
- dmypy
73+
- mypy
74+
- stubgen
75+
package nox 2018.10.17, Python 3.6.2+
76+
- nox
77+
- tox-to-nox
78+
79+
To upgrade or uninstall the package
80+
81+
::
82+
83+
$ pipx upgrade PACKAGE
84+
$ pipx uninstall PACKAGE
85+
86+
``pipx`` can be upgraded or uninstalled with pip
87+
88+
::
89+
90+
$ pip install -U pipx
91+
$ pip uninstall pipx
92+
93+
``pipx`` also allows you to install and run the latest version of a cli tool
94+
in a temporary, ephemeral environment.
95+
96+
::
97+
98+
$ pipx run PACKAGE [ARGS]
99+
100+
For example
101+
102+
::
103+
104+
$ pipx run cowsay moooo
105+
106+
To see the full list of commands ``pipx`` offers, run
107+
108+
::
109+
110+
$ pipx --help
111+
112+
You can learn more about ``pipx`` at its homepage,
113+
https://github.com/pipxproject/pipx.

source/key_projects.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ bandersnatch
2121
`Mailing list <http://mail.python.org/mailman/listinfo/distutils-sig>`__ [2]_ |
2222
`Issues <https://github.com/pypa/bandersnatch/issues>`__ |
2323
`Github <https://github.com/pypa/bandersnatch>`__ |
24-
`PyPI <https://pypi.org/project/bandersnatch>`__ |
24+
`PyPI <https://pypi.org/project/bandersnatch>`__ |
2525
Dev irc:#bandersnatch
2626

2727
bandersnatch is a PyPI mirroring client designed to efficiently create a
@@ -341,6 +341,17 @@ files, standalone Python environments in the spirit of :ref:`virtualenv`.
341341
``#!/usr/bin/env python`` and special :file:`__main__.py`, and are designed to
342342
make deployment of Python applications as simple as ``cp``.
343343

344+
.. _pipx:
345+
346+
pipx
347+
====
348+
349+
`Docs <https://github.com/pipxproject/pipx>`__ |
350+
`Github <https://github.com/pipxproject/pipx>`__ |
351+
`PyPI <https://pypi.org/project/pipx/>`__
352+
353+
pipx is a tool to safely install and run Python CLI applications globally.
354+
344355
.. _scikit-build:
345356

346357
scikit-build

source/tutorials/installing-packages.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ Creating Virtual Environments
161161

162162
Python "Virtual Environments" allow Python :term:`packages <Distribution
163163
Package>` to be installed in an isolated location for a particular application,
164-
rather than being installed globally.
164+
rather than being installed globally. If you are looking to safely install
165+
global command line tools,
166+
see :doc:`/guides/installing-stand-alone-command-line-tools`.
165167

166168
Imagine you have an application that needs version 1 of LibFoo, but another
167169
application requires version 2. How can you use both these applications? If you
@@ -472,7 +474,6 @@ Install `setuptools extras`_.
472474
$ pip install -e .[PDF]==3.0 # editable project in current directory
473475

474476

475-
476477
----
477478

478479
.. [1] "Secure" in this context means using a modern browser or a

0 commit comments

Comments
 (0)