pipx #### * 官网: https://pipx.pypa.io/ * GitHub: https://github.com/pypa/pipx * pipx — Install and Run Python Applications in Isolated Environments .. note:: 一些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. 简介 ==== .. note:: 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'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. * [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. .. warning:: 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 使用 ==== .. figure:: https://img.zhaoweiguo.com/uPic/2024/01/pipx_demo.gif 代码:: >> 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`` 命令