Upgrade package without upgrading dependencies using pip?

后端 未结 3 645
南笙
南笙 2020-12-08 06:04

I\'m using pip and virtualenv for my python application. I would like to upgrade to a new version of the application without touching the dependencies. When I use pip

相关标签:
3条回答
  • 2020-12-08 07:00

    You're right. I thought that when I added --no-deps it had neglected to uninstall the existing version. But I tried it again and see there's no issue:

    $ pip install -U --no-deps myproj
    Downloading/unpacking myproj
      Downloading myproj-1.0-trunk.31072.tar.gz (43Kb): 43Kb downloaded
      Running setup.py egg_info for package myproj
    Installing collected packages: myproj
      Found existing installation: myproj 1.0-trunk.31053
        Uninstalling myproj:
          Successfully uninstalled myproj
      Running setup.py install for myproj
    Successfully installed myproj
    Cleaning up...
    
    0 讨论(0)
  • 2020-12-08 07:03

    I just tried on my virtualenv project and pip install -U --no-deps mypackage seems to work just fine. It just download mypackage and nothing else. What's your set up like?

    0 讨论(0)
  • 2020-12-08 07:04

    Overview:

    • Install new packages without upgrading installed ones: pip install (without -U)
    • Upgrade only packages that are outdated according to requirements: pip install --upgrade --upgrade-strategy only-if-needed (default in new versions)
    • Upgrade package and all dependencies to latest version: pip install --upgrade --upgrade-strategy eager (default in old versions)
    • Install or upgrade listed packages without touching dependencies: --no-deps

    UPDATE (thanks to @Jether's comment): If you're using the latest version of pip, then updating dependencies only when necessary is now the default behavior, and you don't need to do anything special! The answer below outlines the steps for older versions of pip (which also works for newer versions if you want to be portable).

    If you really want to not touch dependencies, then indeed the way to go is

    pip install -U --no-deps mypackage
    

    But I think what you'll usually want is to not upgrade dependencies unless it's required. In that case you can use:

    pip install --upgrade --upgrade-strategy only-if-needed mypackage
    

    This only updates requirements if the package requires a newer version than is installed.

    0 讨论(0)
提交回复
热议问题