Is there a way to update a package and, recursively, all the packages it uses?

Viewed 398

I have created a package for internal use. In my setup file I have something like:

from setuptools import setup, find_packages

setup(
    name='myutils',
    version='0.3',
    description='Set of utils for these projects',
    packages=find_packages(),
    install_requires=[
        'requests',
        'arrow',
        'slackclient'
    ]
)

It works well and it installs all the packages in install_requires smoothly.

However, from time to time some of these packages may need an update, so I expected pip install --upgrade myutils to update the packages in install_requires, while it does not.

Is there a way to do some kind of pip install --upgrade --recursive myutils or similar, so that the inner packages are installed as well? The only workaround I can think of is to define a minimum package version in the form of package>=that_version.X.y.z, but it does not seem to be the most recommended way to do it.

2 Answers

pip somewhat recently (a few years ago now that I check) changed the default strategy for --upgrade -- it used to upgrade the package and any transitive packages but changed to only upgrading the package

fortunately, a new option was added which controls this behaviour: --upgrade-strategy

to restore the old "upgrade everything" approach, you can use pip install --upgrade --upgrade-strategy=eager PKG (the default strategy is only-if-needed)

you can force an upgrade of all installed packages with the following command line on Unix like OS

pip freeze | sed -r -e 's/([^=]+)==.*/\1/' | xargs pip install --upgrade
Related