What is the difference between pipx and using pip install inside a virtual environment?
Asked Answered
R

1

5

I recently used pipx to install a package (That was the recommended install approach for the package). I installed using pip in a virtual environment. I was with the assumption that pipx is in that environment, and then pipx would install the package in the same environment. However, pipx created a environment folder and installed the package there. I had to add the PATH into in order to use that package. This led me to think what the difference between pipx and using pip install inside a virtual environment

Isn't using pip from the virtual environment more convenient to install the package ?

Remunerative answered 27/3, 2024 at 6:22 Comment(6)
Did you try using both? Do you observe differences?Rayborn
pipx.pypa.io/stable/#how-is-it-different-from-pip With pipx you don't need to add every virtual env to $PATH, you only need to add $HOME/.local/bin once (but you're recommended to add this anyway for other needs like pip install --user).Heterolecithal
@Heterolecithal Yes that is what I was thinking as I well. I was just curious whether there is a solid difference between the both.Remunerative
@KarlKnechtel Yes I did try. I used pipx to install poetry also used pip to install it as well. I don't observe any viable difference. That is why I asked the question regarding pipx, hoping it would tell me if there are differences under the hood or those that are not surface levelRemunerative
@Heterolecithal From the link you have mentioned, it says "pipx creates an isolated environment for each application and its associated packages". Hence I asked why not just create an virtual environment and then use pip to install packages in that environment ?Remunerative
@adiaux "I asked why not just create an virtual environment and then use pip to install packages…" pipx creates a virtual env, installs the application and its dependecies and links the application into $HOME/.local/bin, all automatically, with just one command pipx install <app>. With pip you need to do everything manually and add it to $PATH yourself.Heterolecithal
M
7

pipx can be seen as an automation tool or a wrapper around pip and venv to mainly manage isolated virtual environments, install Python cli applications and expose their binaries.

An important difference with pip is that pipx is focused on packages that have at least one entry point to be called from the terminal and does not allow to import and use libraries. For instance, this is not supported:

pipx install <library>
python -c "import <library>"

Another interesting feature of pipx is that it can expose apps to end users that are unfamiliar with Python and virtual environments but are interested in some tool implemented in Python, so after pipx install <tool> they can just type tool and use it right away seamlessly. This way pipx works as a package manager, similar to apt, dnf, brew, and others.

Maclaine answered 11/5, 2024 at 6:35 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.