使用 pyenv,我如何 pip 安装全局 CLI 并使它们即使在 virtualenv 中也可用?

Using pyenv, how can I pip install global CLIs and make them available even when in a virtualenv?

有许多 pip 安装的 CLI,例如 ansibleblack,无论我使用哪个 python 版本或 virtualenv,我都想始终访问它们。如果我将某个 python 安装标记为全局(a la pyenv global 3.10.0),然后我可以使用 pip 将这些 CLI 安装到那个全局 python 的站点包中,当我使用全局 python 时,pyenv 使它们可以运行。但是,一旦我进入 virtualenv,它们就变得不可用了。这使我无法在不将这些工具安装到 virtualenv 中的情况下使用 linting、部署和执行通用系统相关任务的工具,我不想这样做。

是否有解决此问题的受支持或通用方法,以便我可以安装某些包含二进制文件的 pip 包,并让这些二进制文件始终可访问?

Python Packaging Authority has a tool called PipX就是为了这个目的,看看吧!

来自自述文件:

Overview: What is pipx?

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's npx, and Linux's apt.

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.