Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uninstall injected package #67

Closed
schinckel opened this issue Jan 14, 2019 · 16 comments
Closed

Uninstall injected package #67

schinckel opened this issue Jan 14, 2019 · 16 comments

Comments

@schinckel
Copy link

Sometimes I want to uninstall an injected package: for instance, the latest release of tox means that detox is no longer required/supported.

Is there a way to do this?

pipx uninject tox detox

I wonder what the best name for that should be. exclude, expel and withdraw are all cute.

@schinckel
Copy link
Author

In the meantime, you can do $HOME/.local/pipx/<x>/bin/pip uninstall <y>, but that's a bit messy.

@cs01
Copy link
Member

cs01 commented Apr 6, 2019

The runpip command was added in 0.13 which can indirectly do this. Therefore I will close this issue since runpip is a decent workaround.

@cs01 cs01 closed this as completed Apr 6, 2019
@simonw
Copy link

simonw commented Jul 14, 2020

For the record, here's how to do that with runpip (since this issue thread came up first for me in a Google search):

pipx runpip name-of-my-environment uninstall name-of-package

@cs01
Copy link
Member

cs01 commented Jul 14, 2020

I don't personally use pipx inject and was against it initially, but it's proven quite popular. I closed the issue pretty quickly because I'm biased, but I actually think pipx uninject might not be a bad idea. Reopening in case anyone else has thoughts on this.

@cs01 cs01 reopened this Jul 14, 2020
@itsayellow
Copy link
Contributor

👍 for uninject

@cs01
Copy link
Member

cs01 commented Jul 16, 2020

Let’s make uninject happen

@simonw
Copy link

simonw commented Jul 17, 2020

I'd like uninject.

@uranusjr
Copy link
Member

One caveat about uninject is it won’t uninstall dependencies of the injected package, since pip does not know how to do that. But that’s quite well-known at this point anyway so I don’t think it’s a blocker, just something to keep in mind that less-experienced users may have false hopes on.

Does pipx maintain a listed of injected packages in the metadata? We may be able to reconstruct the environment an clean up unneeded packages automatically as well.

@itsayellow
Copy link
Contributor

That's a good point @uranusjr . The metadata indeed contains the main package and a list of all injected packages. It does not keep track of any incidentally-installed dependencies.

To find any dependencies to remove, we could

  1. uninstall the injected package, and then
  2. run pip list --not-required to find all packages that are not depended upon
  3. From the --not-required list, remove the current main package and injected packages
  4. Uninstall the remaining --not-required packages

@itsayellow
Copy link
Contributor

I suppose one risk of the above is if the user did something more "manual" like using a runpip command to install something that we can't keep track of in the metadata.

@uranusjr
Copy link
Member

uranusjr commented Jul 19, 2020

Another approach would be to make the clean-up behaviour explicit to the user, a la apt autoremove. pipx uninject only uninstalls the injected package by default, not its dependencies, but shows a messages listing seemingly unneeded packages in the environment, promping the user to run pipx clean to uninstall them. uninject can also have a --clean flag that does this automatically, like apt remove --auto-remove.

@cs01
Copy link
Member

cs01 commented Aug 30, 2020

Another approach would be to make the clean-up behaviour explicit to the user, a la apt autoremove. pipx uninject only uninstalls the injected package by default, not its dependencies, but shows a messages listing seemingly unneeded packages in the environment, promping the user to run pipx clean to uninstall them. uninject can also have a --clean flag that does this automatically, like apt remove --auto-remove.

Agreed, I like this

@patrickmburrell
Copy link

+1 for uninject

@itsayellow
Copy link
Contributor

Another approach would be to make the clean-up behaviour explicit to the user, a la apt autoremove. pipx uninject only uninstalls the injected package by default, not its dependencies, but shows a messages listing seemingly unneeded packages in the environment, promping the user to run pipx clean to uninstall them. uninject can also have a --clean flag that does this automatically, like apt remove --auto-remove.

What about making the default to remove dependencies of an uninjected app, but allow for the possibility to leave the dependencies alone (e.g. --leave-deps)

I like this better for the pipx use case. In fact I can't really imagine why a pipx user would want to leave the dependencies behind. It's not the same as a generic venv where the user is adding and removing random packages. In the pipx case, a user may inject a particular package because they want that functionality, but it doesn't seem likely to me that if they decide against that functionality and uninject, that it would be common to want to still use the dependencies of that package.

If they did want a particular dependency of an injected package they could inject that dependency explicitly, which is the action I would expect. In which case we would leave it installed because our metadata shows it is an injected package.

I'm working on a branch right now for uninject, and the above is how I've implemented it. It works very cleanly so far.

@Sispheor
Copy link

Hello people.
Where are we on this?
The command to remove via runpip works, but the package is still referenced then in the pipx list --include-injected

pipx runpip ansible-4 uninstall ansible-lint
pipx list --include-injected
 package ansible 4.9.0 (ansible-4), Python 3.8.5
    - ansible-4
    - ansible-config-4
    - ansible-connection-4
    - ansible-console-4
    - ansible-doc-4
    - ansible-galaxy-4
    - ansible-inventory-4
    - ansible-playbook-4
    - ansible-pull-4
    - ansible-test-4
    - ansible-vault-4
    Injected Packages:
      - ansible-lint 5.3.2
      - ansible-modules-hashivault 4.6.5
      - hvac 0.10.14
      - kubernetes 20.13.0
      - python-ldap 3.4.0
      - pyvim 3.0.2
      - pyvmomi 7.0.2
      - vSphere-Automation-SDK 1.71.0

@cs01
Copy link
Member

cs01 commented Feb 16, 2022

Matthew is no longer able to dedicate time to pipx, so I guess his branch will not be merged. PRs are welcome from the community.

@cs01 cs01 closed this as completed Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants