pypa / pipx

Install and Run Python Applications in Isolated Environments
https://pipx.pypa.io
MIT License
9.51k stars 396 forks source link

pipx ensurepath appends to PATH. Option to prepend ? #1424

Closed paugier closed 2 weeks ago

paugier commented 1 month ago

How would this feature be useful?

pipx ensurepath appends the pipx path to the user paths (https://github.com/pypa/pipx/blob/main/src/pipx/commands/ensure_path.py#L64). I understand that it is a reasonable default.

However, if one wants to hide a system installed command with a pipx installed one, the pipx path needs to be prepended to $PATH. For example, if an old version of Mercurial is installed (/usr/bin/hg) and I want to use a newer Mercurial managed with pipx.

Describe the solution you'd like

There could be an option to ensurepath so that the pipx path would be preprended. Something like:

pipx ensurepath --prepend

Note that there is userpath.prepend similar to userpath.append so the implementation would be straightforward.

paugier commented 1 month ago

I would be very interested to get a feedback about this possible feature. It seems to me that it would be a very useful feature. I think I could submit a simple PR but I'd like first to get feedback about the idea.

huxuan commented 1 month ago

I would be very interested to get a feedback about this possible feature. It seems to me that it would be a very useful feature. I think I could submit a simple PR but I'd like first to get feedback about the idea.

pr is always welcome. I am ok to have this feature, it is just like venv, venv should take precedence over system site packages.

agriyakhetarpal commented 3 weeks ago

Hi! I was interested in this feature as well, and I put together a PR (#1451).