TOC

pipx: 虚拟环境版本的 pip

pipx 和 pip 一样,也是来自 PyPA 的项目。
PS: PyPA 的知名项目包括 pipenv, pip, pipx, virtualenv, flit, twine。

pipx 的作用是将包安装在虚拟环境中(利用标准库中的 venv)。用来安装一些 Python 写的工具就很好,不需要关心这些工具的代码时。

pip install pipx

# Ensure directories necessary for pipx operation are in your PATH environment variable.
pipx ensurepath

# 可以按照它的提示配置 Shell 自动完成
pipx completions

示例

$ pipx install --pip-args="-U" youtube-dl
⚠️  File exists at /home/catroll/.local/bin/youtube-dl and points to /home/catroll/.local/bin/youtube-dl, not
    /home/catroll/.local/pipx/venvs/youtube-dl/bin/youtube-dl. Not modifying.
  installed package youtube-dl 2021.6.6, installed using Python 3.9.7
    - youtube-dl (symlink missing or pointing to unexpected location)
done! ✨ 🌟 ✨

$ pipx install --pip-args="-U" youtube-dl
'youtube-dl' already seems to be installed. Not modifying existing installation in '/home/catroll/.local/pipx/venvs/youtube-dl'. Pass '--force' to force
installation.

$ pipx install --pip-args="-U" --force youtube-dl
Installing to existing venv 'youtube-dl'
⚠️  Note: youtube-dl was already on your PATH at /usr/local/bin/youtube-dl
  installed package youtube-dl 2021.6.6, installed using Python 3.9.7
  These apps are now globally available
    - youtube-dl
done! ✨ 🌟 ✨

$ type youtube-dl
youtube-dl is /home/catroll/.local/bin/youtube-dl

$ ll /home/catroll/.local/bin/youtube-dl
lrwxrwxrwx 1 catroll catroll 57 2022-01-13 08:35:57 /home/catroll/.local/bin/youtube-dl -> /home/catroll/.local/pipx/venvs/youtube-dl/bin/youtube-dl
$ pipx install -f thefuck
Installing to existing venv 'thefuck'
  installed package thefuck 3.31, installed using Python 3.9.7
  These apps are now globally available
    - fuck
    - thefuck
done! ✨ 🌟 ✨