3

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.

fedorqui
  • 275,237
  • 103
  • 548
  • 598
  • 1
    I hope someone will show a better solution. Solutions, that I know, are just shell scripts building the necessary pip command. See for example the pipdeptree package mentioned here: https://stackoverflow.com/a/24903067/5378816 – VPfB Sep 25 '20 at 11:12
  • if your package requires a particular version of a required package specify the version number, or just specify the latest version that you know. The links does not tell the recommended way only the diff between `install_requires` and `requirements.txt` – rioV8 Sep 25 '20 at 11:20
  • thanks, @rioV8. Going through the other question I could see references to not pinning a version and I somehow got the impression that specifying versions there is not its main purpose. I might be wrong. – fedorqui Sep 25 '20 at 11:53

2 Answers2

4

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)

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
1

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
rioV8
  • 24,506
  • 3
  • 32
  • 49