|
| 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. |
0 commit comments