Tuesday, April 19, 2022

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

Issue

There are many pip-installed CLI's like ansible and black that I want to have access to always, no matter which python version or virtualenv I am using. If I mark a certain python installation as global (a la pyenv global 3.10.0), I can then use pip to install these CLI's into that global python's site-packages, and pyenv makes them runnable while I'm using the global python. However, they become unavailable once I'm inside a virtualenv. This makes me no longer able to use tools for linting, deploying, and doing generic system-related tasks without installing these tools into the virtualenv, which I do not want to do.

Is there a supported or common way of solving this problem so that I can install certain pip packages which include binaries, and have those binaries always accessible?


Solution

The Python Packaging Authority has a tool called PipX which is meant for exactly this purpose, check it out!

From the readme:

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.



Answered By - tzaman
Answer Checked By - Timothy Miller (WPSolving Admin)