pip: upgrade package without upgrading particular

2019-03-16 06:18发布

问题:

My question is very much similar to this question. But It differs in a way that if i am installing some package i only want to disable upgrade for a particular dependency not for all dependencies. I know there is a flag --no-deps but it will exclude all dependency rather i just want to exclude one.

Here is a scenario:

  • I have Django 1.4 installed
  • I have django-rosetta installed

Here are django-rosetta dependencies in latest build:

install_requires=[
    'six >=1.2.0',
    'Django >= 1.3'
]

Now i want to upgrade rosetta pip install -U django-rosetta. But it tried to download and install Django 1.5 because in rosetta dependency Django >= 1.3 is required (and i don't want it to do this as Django 1.4 is already installed) I only want it to upgrade six package if there is any.

--no-deps flag will not work as it will exclude six package also. Also I am not using virtual environment. Any suggestions please?

回答1:

This works and lets you be more precise:

pip install -U django-rosetta Django==1.4


回答2:

Create a requirement file requirement.txt containing:

Django==1.4

then

pip install -U django-rosetta -r requirement.txt