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

ENH Add support for reinstalling packages #64

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

ryanking13
Copy link
Member

@ryanking13 ryanking13 commented Apr 25, 2023

Resolve #51

This PR changes micropip.install behavior to remove previously installed packages and reinstall the new version. In addition, it adds the force_reinstall parameter to micropip.install, allowing it to force a reinstall even if it already meets the requirements.

Edit:

This PR adds reinstall parameter to micropip.install which allows reinstalling packages that are already installed.

  • changelog
  • refactorings

@ryanking13
Copy link
Member Author

ryanking13 commented Apr 25, 2023

@rth I just noticed that you added sprint label in #51. Maybe there is a sprint running in PyconUS? Sorry if I hijacked someones work.

@rth
Copy link
Member

rth commented Apr 25, 2023

Yes, there is a sprint in PyConUS so I tagged a few issues people have more to choose from. No worries if you took it :)

@hoodmane
Copy link
Member

Thanks @ryanking13!

remove previously installed packages and reinstall the new version

I don't think this makes sense as a default. In my opinion it should not reinstall anything unless it is specifically requested.

@ryanking13
Copy link
Member Author

I don't think this makes sense as a default. In my opinion it should not reinstall anything unless it is specifically requested.

Maybe my description was not clear. It uninstalls only if the requested version is incompatible with the installed version. Previously in such cases, micropip failed with:

ValueError: Requested 'packaging==22.0', but packaging==23.0 is already installed

Copy link
Member

@hoodmane hoodmane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think failing is better by default than reinstall. I think people really mostly don't want to reinstall packages that they've already imported but they might not realize they don't want to. Maybe having an allow reinstall flag would be good.

At the wasm summit they were asking if they could test packaging against wasm and I was like sure easy but then the command line runner had some weird crash...

@rth
Copy link
Member

rth commented Apr 25, 2023

If True, reinstall all packages even if they are already up-to-date.

Yeah, I'm also not sure about it. As a user, in the example above I would expect the install command to only change the packages that need changing and that I requested. But I guess it's more complex in terms of dependency resolution. This feels like re-installing a venv, which is good but strange to do in Python when not managing venv.

If we take the case where we install some packages. Some are already installed with different versions. If the version is compatible we do nothing, if it isn't we uninstall them, and install the requested version (and leave all other packages unchanged). That's more or less what pip does (or used to do) by default. Can't we do that?

@ryanking13
Copy link
Member Author

ryanking13 commented Apr 26, 2023

I still think failing is better by default than reinstall. I think people really mostly don't want to reinstall packages that they've already imported but they might not realize they don't want to. Maybe having an allow reinstall flag would be good.

Hmm, yes. Unlike other package managers micropip is a runtime package manager so the situation is more complex that some packages might be already imported... and we don't show any logs (unless verbose option is enabled in #60), so people will not even notice that some packages are reinstalled.

If we take the case where we install some packages. Some are already installed with different versions. If the version is compatible we do nothing, if it isn't we uninstall them, and install the requested version (and leave all other packages unchanged). That's more or less what pip does (or used to do) by default. Can't we do that?

Yes, that is the current expected bahavior but I guess Hood does not prefer uninstalling packages without an explicit flag?

@ryanking13
Copy link
Member Author

ryanking13 commented Apr 26, 2023

Then how about:

  1. (default) micropip.install(reinstall=False) will show error messages if there is an installed version that is incompatible.

  2. micropip.install(reinstall=True) will reinstall packages that are incompatible / keep packages that are compatible (same as pip)

    • maybe show logging messages by default so that people can aware which packages are reinstalled?

@hoodmane
Copy link
Member

hoodmane commented May 8, 2023

Hood does not prefer uninstalling packages without an explicit flag?

Well if it's for matching pip then I could sort of see it. But the issue is just what happens if the package is already imported...

@ryanking13
Copy link
Member Author

Well if it's for matching pip then I could sort of see it. But the issue is just what happens if the package is already imported...

Well jupyter shares the same problem and users would need to call importlib.reload if they have already imported a package. One difference is that pip is verbose by default while micropip is silent so users might not notice that they have reinstalled a package.

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

Successfully merging this pull request may close these issues.

Ability to reinstall a different version of a package
3 participants