Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pip: upgrade package without upgrading particular dependency

Tags:

python

pip

django

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?

like image 955
Aamir Rind Avatar asked Jun 20 '13 10:06

Aamir Rind


People also ask

How do I upgrade pip packages?

Update a package: pip install --upgrade To update installed packages to the latest version, run pip install with the --upgrade or -U option.

How do I upgrade a Python package to a specific version?

How do I Install a Specific Version of a Python Package? To install a specific version of a Python package you can use pip: pip install YourPackage==YourVersion . For example, if you want to install an older version of Pandas you can do as follows: pip install pandas==1.1.

Does pip install all dependencies?

Pip relies on package authors to stipulate the dependencies for their code in order to successfully download and install the package plus all required dependencies from the Python Package Index (PyPI).

Does pip update requirements txt?

this will automatically upgrade all packages from requirements. txt (make sure to install pip-tools using pip install command).

How to automate your dependencies with pipupgrade?

Automate your Dependencies by installing pipupgrade in your CI workflow. Zero Dependencies! Check out installation for more details. Upgrades all the packages across all detected pip environments. Upgrades pipupgrade. Upgrades all the packages within the defined pip environment.

Is there a way to upgrade pip install without--upgrade?

Doing just pip install without --upgrade does not fix any broken dependencies. And with --upgrade then it goes to the latest version (so not minimal changes I would want). Is there some reason you can't do something equivalent to: Aside: current default upgrade strategy is only-if-needed.

What does pip install-U-no-Deps do?

When I use pip install -U, it tries to upgrade all the packages, and even uninstalls and re-installs the same version of a dependency package when there isn't a new version available. I also tried pip install -U --no-deps but that seems equivalent to a regular install instead of an upgrade. Is there a combination of flags that will do what I want?

When should I update dependencies in Pip?

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).


2 Answers

This works and lets you be more precise:

pip install -U django-rosetta Django==1.4
like image 134
gordonc Avatar answered Oct 06 '22 14:10

gordonc


Create a requirement file requirement.txt containing:

Django==1.4

then

pip install -U django-rosetta -r requirement.txt
like image 8
Guillaume Avatar answered Oct 06 '22 14:10

Guillaume