Installing stand alone command line tools#

Many packages provide command line applications. Examples of such packages are mypy, flake8, black, and Pipenv.

Usually you want to be able to access these applications from anywhere on your system, but installing packages and their dependencies to the same global environment can cause version conflicts and break dependencies the operating system has on Python packages.

pipx solves this by creating a virtual environment for each package, while also ensuring that its applications are accessible through a directory that is on your $PATH. This allows each package to be upgraded or uninstalled without causing conflicts with other packages, and allows you to safely run the applications from anywhere.

Примітка

pipx only works with Python 3.6+.

pipx is installed with pip:

python3 -m pip install --user pipx
python3 -m pipx ensurepath
py -m pip install --user pipx
py -m pipx ensurepath

Примітка

ensurepath ensures that the application directory is on your $PATH. You may need to restart your terminal for this update to take effect.

Now you can install packages with pipx install and run the package’s applications(s) from anywhere.

$ pipx install PACKAGE
$ PACKAGE_APPLICATION [ARGS]

For example:

$ pipx install cowsay
  installed package cowsay 6.1, installed using Python 3.12.2
  These apps are now globally available
    - cowsay
done! ✨ 🌟 ✨
$ cowsay -t moo
  ___
< moo >
  ===
        \
         \
           ^__^
           (oo)\_______
           (__)\       )\/
               ||     ||
               ||----w |

To see a list of packages installed with pipx and which applications are available, use pipx list:

$ pipx list
venvs are in /Users/user/Library/Application Support/pipx/venvs
apps are exposed on your $PATH at /Users/user/.local/bin
manual pages are exposed at /Users/user/.local/share/man
   package black 24.2.0, installed using Python 3.12.2
    - black
    - blackd
   package cowsay 6.1, installed using Python 3.12.2
    - cowsay
   package mypy 1.9.0, installed using Python 3.12.2
    - dmypy
    - mypy
    - mypyc
    - stubgen
    - stubtest
   package nox 2024.3.2, installed using Python 3.12.2
    - nox
    - tox-to-nox

To upgrade or uninstall a package:

pipx upgrade PACKAGE
pipx uninstall PACKAGE

pipx can be upgraded or uninstalled with pip:

python3 -m pip install --upgrade pipx
python3 -m pip uninstall pipx
py -m pip install --upgrade pipx
py -m pip uninstall pipx

pipx also allows you to install and run the latest version of an application in a temporary, ephemeral environment. For example:

pipx run cowsay -t moooo

To see the full list of commands pipx offers, run:

pipx --help

You can learn more about pipx at https://pipx.pypa.io/.