r/learnpython • • 2d ago

pip vs pipx

as far as I understand pip just installs the package while pipx installs the executable and creates an environment but why create an environment in the first place? Is it so that when someone else runs the program and there are changes in the package the program might break but an isolated package is protected in the environment?

0 Upvotes

11 comments sorted by

11

u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 2d ago

pipx is basically used to run (and install/cache) tools, with each tool getting an independent virtual environment. pip is primarily for installing project dependencies, though you can also use it to install things globally if you needed to for some reason.

That being said, uv has largely replaced both tools.

1

u/SharkSymphony 2d ago

I think you have the gist of it? Pipx allows different Python apps with different versions of the same dependencies to be installed without clobbering each others' dependencies.

1

u/UwUfit 1d ago

I've been recommended UV instead of pip (UV still supports pip). Great venv management and very fast. No more requirements.txt and no more anaconda for me

-1

u/brasticstack 2d ago

pip already requires a virtual environment. The reason is so you can have multiple python projects, each with their own set of dependencies, without encountering conflicts due to a one project needing a different version of a dependency than another project.

pipx can install different Python versions, iirc, and may manage virtual envs for you.

7

u/SharkSymphony 2d ago

Pip does not require a virtual environment! You can use pip just fine with the system installation, so long as it has the appropriate access privileges.

2

u/brasticstack 2d ago

Modern versions give a nag at the least, but I thought disallowed installation without a virtualenv. Admittedly I always work in a venv and haven't really tried otherwise in years.

2

u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 2d ago

On Linux distros that depend on Python, and Mac OS, you would be correct in that pip by default prevents you from installing packages to the system Python installation to avoid accidentally breaking things (this can be bypassed with an appropriately named flag; --break-system-packages IIRC), but it will happily install anything globally to any Python installations you manage yourself.

On Windows, there's no restriction because Windows does not depend on Python in any way.

Granted, using virtual environments is generally the best practice, and tools like uv and poetry largely abstract away all this.

0

u/DanceHackRock 1d ago

Try Pipenv.

1

u/JamzTyson 1d ago

That's a totally different program for a totally different purpose.

1

u/DanceHackRock 1d ago

Strange. Since I'm using Pipenv I don't use pip anymore.