pypa / pip

The Python package installer
https://pip.pypa.io/
MIT License
9.52k stars 3.03k forks source link

Command - pip reset #12694

Open fakabbir opened 6 months ago

fakabbir commented 6 months ago

What's the problem this feature will solve?

Problem: Once packages are installed, there is not way to come to the starting point in base environement except creating a new virtual env

Solution: pip reset command would uninstall all the libraries which are not installed as a base package.

Describe the solution you'd like

A pip reset commnand

Alternative Solutions

pip uninstall command can be more powerfull

Additional context

Requires creating venv in case the base python has a lots of packages and is not maintained well

Code of Conduct

pfmoore commented 6 months ago

Deleting and recreating a virtual environment is, by design, a fast operation. The proposed pip subcommand would merely be a slower way of doing the same thing. Thanks for the suggestion but I don’t think it’s something we would want to spend our limited bandwidth on.

pradyunsg commented 6 months ago

https://github.com/pradyunsg/dotfiles/blob/main/src/python/.zsh/8-v.symlink.zsh#L111

This is something that could be done externally to pip today, like I have in the link above.

@pfmoore while I agree with your assessment here, I will say that this issue represents a desire for a lower-effort way of doing things. Specifically, that recreating a virtual environment requires knowing/typing the path or some substitute and it's often nice to not have to think about details like that.

fakabbir commented 6 months ago

Its more of a way to revert the base environment, which is generally used by default

pfmoore commented 6 months ago

When you say the “base environment”, do you mean the system Python, i.e. not a virtual environment? If so, then generally the advice is not to install packages direct into the base environment - in many cases, you should be managing that environment using a system package manager rather than pip anyway.

But if you do need to do that, a script such as the one @pradyunsg linked to, is probably the best way.

fakabbir commented 6 months ago

When you say the “base environment”, do you mean the system Python, i.e. not a virtual environment? If so, then generally the advice is not to install packages direct into the base environment - in many cases, you should be managing that environment using a system package manager rather than pip anyway.

But if you do need to do that, a script such as the one @pradyunsg linked to, is probably the best way.

Yes, the script helps.

uranusjr commented 6 months ago

I think one thing to note is deleting all (pip-)installed packages does not equal to blanking the environment, especially if the environment is shared (not isolated to one specific use case). If the environment is a virtual environment, a script wiping sys.prefix and recreating a virutal environment in-place is better in every way. If the goal is explicitly uninstalling all pip-installed packages, pip reset mis-describes what is actually done, and something like pip uninstall :all: would be better.