Install and execute isolated Python applications as regular user.
Operating system version.
$ lsb_release -a
No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04.2 LTS Release: 22.04 Codename: jammy
Python version.
$ python3 --version
Python 3.10.6
Installation
Software details.
$ apt info pipx
Package: pipx Version: 1.0.0-1 Priority: optional Section: universe/python Source: python-pipx Origin: Ubuntu Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Original-Maintainer: Debian Python Team <team+python@tracker.debian.org> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 900 kB Depends: python3-venv, python3-argcomplete, python3-importlib-metadata | python3 (>> 3.8), python3-packaging, python3-userpath, python3:any Recommends: fonts-font-awesome (>= 5.0.10+really4.7.0~dfsg-4.1), libjs-bootstrap4 (>= 4.6.0+dfsg1-4), libjs-highlight.js, libjs-jquery (>= 3.5.1+dfsg+~3.5.5-8), libjs-lunr (>= 2.3.9~dfsg-1), mkdocs (>= 1.1.2+dfsg-1) Homepage: https://github.com/pypa/pipx Download-Size: 371 kB APT-Manual-Installed: yes APT-Sources: http://pl.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages Description: execute binaries from Python packages in isolated environments pipx allows you to... . * Run the latest version of a CLI application from a package in a temporary virtual environment, leaving your system untouched after it finishes. * Install packages to isolated virtual environments, while globally exposing their CLI applications so you can run them from anywhere. * Easily list, upgrade, and uninstall packages that were installed with pipx. . pipx runs with regular user permissions, never calling "sudo pip install".
Install pipx
application.
$ sudo apt install pipx
Display usage information.
$ pipx --help
usage: pipx [-h] [--version] {install,inject,upgrade,upgrade-all,uninstall,uninstall-all,reinstall,reinstall-all,list,run,runpip,ensurepath,completions} ... Install and execute apps from Python packages. Binaries can either be installed globally into isolated Virtual Environments or run directly in a temporary Virtual Environment. Virtual Environment location is /home/milosz/.local/pipx/venvs. Symlinks to apps are placed in /home/milosz/.local/bin. optional environment variables: PIPX_HOME Overrides default pipx location. Virtual Environments will be installed to $PIPX_HOME/venvs. PIPX_BIN_DIR Overrides location of app installations. Apps are symlinked or copied here. USE_EMOJI Overrides emoji behavior. Default value varies based on platform. PIPX_DEFAULT_PYTHON Overrides default python used for commands. options: -h, --help show this help message and exit --version Print version and exit subcommands: Get help for commands with pipx COMMAND --help {install,inject,upgrade,upgrade-all,uninstall,uninstall-all,reinstall,reinstall-all,list,run,runpip,ensurepath,completions} install Install a package inject Install packages into an existing Virtual Environment upgrade Upgrade a package upgrade-all Upgrade all packages. Runs `pip install -U` for each package. uninstall Uninstall a package uninstall-all Uninstall all packages reinstall Reinstall a package reinstall-all Reinstall all packages list List installed packages run Download the latest version of a package to a temporary virtual environment, then run an app from it. Also compatible with local `__pypackages__` directory (experimental). runpip Run pip in an existing pipx-managed Virtual Environment ensurepath Ensure directories necessary for pipx operation are in your PATH environment variable. completions Print instructions on enabling shell completions for pipx
Ensure that PATH
will include directory with installed applications.
$ pipx ensurepath
Success! Added /home/milosz/.local/bin to the PATH environment variable. Consider adding shell completions for pipx. Run 'pipx completions' for instructions. You will need to open a new terminal or re-login for the PATH changes to take effect. Otherwise pipx is ready to go! โจ ๐ โจ
$ cat ~/.bashrc
[...] # Created by `pipx` on 2023-04-01 16:41:58 export PATH="$PATH:/home/milosz/.local/bin
Determine how to enable autocompletion.
$ pipx completions
Add the appropriate command to your shell's config file so that it is run on startup. You will likely have to restart or re-login for the autocompletion to start working. bash: eval "$(register-python-argcomplete pipx)" zsh: To activate completions for zsh you need to have bashcompinit enabled in zsh: autoload -U bashcompinit bashcompinit Afterwards you can enable completion for pipx: eval "$(register-python-argcomplete pipx)" tcsh: eval `register-python-argcomplete --shell tcsh pipx` fish: # Not required to be in the config file, only run once register-python-argcomplete --shell fish pipx >~/.config/fish/completions/pipx.fish
Enable autocompletion inside current Bash shell. It requires python3-argcomplete
package which should be already installed.
$ eval "$(register-python-argcomplete3 pipx)"
Ensure that autocompletion will be available by default.
$ echo 'eval "$(register-python-argcomplete3 pipx)"' | tee --append ~/.bashrc
Execute Python application
Display usage information.
$ pipx run --help
usage: pipx run [-h] [--no-cache] [--pypackages] [--spec SPEC] [--verbose] [--python PYTHON] [--system-site-packages] [--index-url INDEX_URL] [--editable] [--pip-args PIP_ARGS] app ... Download the latest version of a package to a temporary virtual environment, then run an app from it. The environment will be cached and re-used for up to 14 days. This means subsequent calls to 'run' for the same package will be faster since they can re-use the cached Virtual Environment. In support of PEP 582 'run' will use apps found in a local __pypackages__ directory, if present. Please note that this behavior is experimental, and acts as a companion tool to pythonloc. It may be modified or removed in the future. See https://github.com/cs01/pythonloc. positional arguments: app ... app/package name and any arguments to be passed to it options: -h, --help show this help message and exit --no-cache Do not re-use cached virtual environment if it exists --pypackages Require app to be run from local __pypackages__ directory --spec SPEC The package name or specific installation source passed to pip. Runs `pip install -U SPEC`. For example `--spec mypackage==2.0.0` or `--spec git+https://github.com/user/repo.git@branch` --verbose --python PYTHON The Python version to run package's CLI app with. Must be v3.6+. --system-site-packages Give the virtual environment access to the system site-packages dir. --index-url INDEX_URL, -i INDEX_URL Base URL of Python Package Index --editable, -e Install a project in editable mode --pip-args PIP_ARGS Arbitrary pip arguments to pass directly to pip install/upgrade commands
Download and execute application in a temporary virtual environment,
$ pipx run --spec httpie https GET pie.dev/ip
HTTP/1.1 200 OK Access-Control-Allow-Credentials: true Access-Control-Allow-Origin: * CF-Cache-Status: DYNAMIC CF-RAY: 7b124457c95335be-WAW Connection: keep-alive Content-Length: 31 Content-Type: application/json Date: Sat, 01 Apr 2023 16:39:13 GMT NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800} Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=d1GfzfNNhTPStMs7G7zxFCRYIb7CNTfcPAPRlfmV80pygyR8p%2FSK4X6sSmYT6L0JudMrqmv2cmpDtPhBc%2BpgDbI8LFoPJcUVUQNgAiXQejuZsshwEjStU19v"}],"group":"cf-nel","max_age":604800} Server: cloudflare alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400 { "origin": "1.2.3.4" }
Install Python application
Display usage information.
$ pipx install --help
usage: pipx install [-h] [--include-deps] [--verbose] [--force] [--suffix SUFFIX] [--python PYTHON] [--system-site-packages] [--index-url INDEX_URL] [--editable] [--pip-args PIP_ARGS] package_spec The install command is the preferred way to globally install apps from python packages on your system. It creates an isolated virtual environment for the package, then ensures the package's apps are accessible on your $PATH. The result: apps you can run from anywhere, located in packages you can cleanly upgrade or uninstall. Guaranteed to not have dependency version conflicts or interfere with your OS's python packages. 'sudo' is not required to do this. pipx install PACKAGE_NAME pipx install --python PYTHON PACKAGE_NAME pipx install VCS_URL pipx install ./LOCAL_PATH pipx install ZIP_FILE pipx install TAR_GZ_FILE The PACKAGE_SPEC argument is passed directly to `pip install`. The default virtual environment location is /home/milosz/.local/pipx and can be overridden by setting the environment variable `PIPX_HOME` (Virtual Environments will be installed to `$PIPX_HOME/venvs`). The default app location is /home/milosz/.local/bin and can be overridden by setting the environment variable `PIPX_BIN_DIR`. The default python executable used to install a package is /usr/bin/python3 and can be overridden by setting the environment variable `PIPX_DEFAULT_PYTHON`. positional arguments: package_spec package name or pip installation spec options: -h, --help show this help message and exit --include-deps Include apps of dependent packages --verbose --force, -f Modify existing virtual environment and files in PIPX_BIN_DIR --suffix SUFFIX Optional suffix for virtual environment and executable names. NOTE: The suffix feature is experimental and subject to change. --python PYTHON The Python executable used to create the Virtual Environment and run the associated app/apps. Must be v3.6+. --system-site-packages Give the virtual environment access to the system site-packages dir. --index-url INDEX_URL, -i INDEX_URL Base URL of Python Package Index --editable, -e Install a project in editable mode --pip-args PIP_ARGS Arbitrary pip arguments to pass directly to pip install/upgrade commands
Install an application.
$ pipx install black==23.1.0
installed package black 23.1.0, installed using Python 3.10.6 These apps are now globally available - black - blackd done! โจ ๐ โจ
Use installed application.
$ black --check /usr/lib/python3/dist-packages/apt
would reformat /usr/lib/python3/dist-packages/apt/__init__.py would reformat /usr/lib/python3/dist-packages/apt/cdrom.py would reformat /usr/lib/python3/dist-packages/apt/auth.py would reformat /usr/lib/python3/dist-packages/apt/progress/base.py would reformat /usr/lib/python3/dist-packages/apt/progress/text.py would reformat /usr/lib/python3/dist-packages/apt/cache.py would reformat /usr/lib/python3/dist-packages/apt/utils.py would reformat /usr/lib/python3/dist-packages/apt/debfile.py would reformat /usr/lib/python3/dist-packages/apt/package.py Oh no! ๐ฅ ๐ ๐ฅ 9 files would be reformatted, 1 file would be left unchanged.
List installed applications.
$ pipx list
venvs are in /home/milosz/.local/pipx/venvs apps are exposed on your $PATH at /home/milosz/.local/bin package black 23.1.0, installed using Python 3.10.6 - black - blackd
List installed applications using JSON format.
$ pipx list --json
{ "pipx_spec_version": "0.1", "venvs": { "black": { "metadata": { "injected_packages": {}, "main_package": { "app_paths": [ { "__Path__": "/home/milosz/.local/pipx/venvs/black/bin/black", "__type__": "Path" }, { "__Path__": "/home/milosz/.local/pipx/venvs/black/bin/blackd", "__type__": "Path" } ], "app_paths_of_dependencies": {}, "apps": [ "black", "blackd" ], "apps_of_dependencies": [], "include_apps": true, "include_dependencies": false, "package": "black", "package_or_url": "black==23.1.0", "package_version": "23.1.0", "pip_args": [], "suffix": "" }, "pipx_metadata_version": "0.2", "python_version": "Python 3.10.6", "venv_args": [] } } } }
Upgrade an application.
$ pipx upgrade black
upgraded package black from 23.1.0 to 23.3.0 (location: /home/milosz/.local/pipx/venvs/black) milosz@laptop:~/Dokumenty/Notatki$ pipx list venvs are in /home/milosz/.local/pipx/venvs apps are exposed on your $PATH at /home/milosz/.local/bin package black 23.3.0, installed using Python 3.10.6 - black - blackd
Uninstall an application.
$ pipx uninstall black
uninstalled black! โจ ๐ โจ