- 官网: https://pipx.pypa.io/
- GitHub: https://github.com/pypa/pipx
- pipx — Install and Run Python Applications in Isolated Environments
注:一些Python写的命令行工具(如mypy, flake8, black, and Pipenv),期望在os的任何地方运行,但如果都安装到 global environment 会造成版本依赖冲突等问题。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.
简介
注:pipx only works with Python 3.6+.
- pipx is a tool to help you install and run end-user applications written in Python. It’s roughly similar to macOS’s
brew, JavaScript’snpx, and Linux’sapt. - It’s closely related to pip. In fact, it uses pip, but is focused on installing and managing Python packages that can be run from the command line directly as applications.
- [How is it Different from pip?] → pip is a general-purpose package installer for both libraries and apps with no environment isolation. pipx is made specifically for application installation, as it adds isolation yet still makes the apps available in your shell: pipx creates an isolated environment for each application and its associated packages.
警告:It is not recommended to install pipx via pipx. If you’d like to do this anyway, take a look at the pipx-in-pipx project and read about the limitations there.
安装
brew install pipx
// Ubuntu 23.04 or above
sudo apt install pipx
// Ubuntu 22.04 or below
python3 -m pip install --user pipx
// windows
scoop install pipx使用

代码:
>> pipx install pycowsay
installed package pycowsay 2.0.3, Python 3.7.3
These apps are now globally available
- pycowsay
done! ✨ 🌟 ✨
>> pipx list
venvs are in /home/user/.local/share/pipx/venvs
apps are exposed on your $PATH at /home/user/.local/bin
package pycowsay 2.0.3, Python 3.7.3
- pycowsay
# Now you can run pycowsay from anywhere
>> pycowsay mooo
____
< mooo >
====
\
\
^__^
(oo)\_______
(__)\ )\/\
||----w |
|| ||命令 pipx run APP [ARGS...]:
// Notice that you don't need to execute any install commands to run the app.
> pipx run pycowsay moo
---
< moo >
---
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||示例
- 参见
demo_python中的pipx命令
与 pip / uv 的边界
- pipx vs pip:pip 装的包全部落在同一个(虚拟)环境里,多个 CLI 工具共享依赖容易互相冲突;pipx 给每个应用单独建一个隔离环境,但对外只暴露可执行命令,用起来感觉像全局安装。库该用 pip 装,能在命令行直接跑的应用工具用 pipx 装。
- pipx vs uv:
uv tool install/uvx是 uv 生态里对标 pipx 的能力,语义几乎一致(uvx=uv tool run),但由 uv 的 Rust 实现驱动,安装和启动速度更快。如果项目/机器已经在用 uv,没必要再额外装 pipx,两者选一即可,避免同类工具用两套管理。
现代项目推荐组合
- 全局常用 CLI 工具(black、httpie、cookiecutter 等):
pipx install <tool>一次安装,随处可用,环境互不污染。 - 只是想临时试一下某个工具、不想留痕:
pipx run <tool>(或等价的uvx <tool>),跑完不留安装记录。 - 已经全面转向 uv 的项目/团队:直接用
uvx/uv tool install代替 pipx,减少工具链数量。
踩坑点
- 不要用
pipx install pipx给自己套娃安装,官方明确不推荐(参见 pipx-in-pipx 的已知限制)。 - pipx 安装的应用默认路径在
~/.local/share/pipx/venvs,可执行文件软链到~/.local/bin,如果这个目录没加入$PATH,装完命令会找不到,需要手动pipx ensurepath。 - pipx 只解决”跑通命令”,不解决”作为库被 import”的场景——如果既要在命令行跑又要在代码里 import 同一个包,pipx 的隔离环境不适用,应该用项目自己的虚拟环境(venv/uv/poetry)装。