Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrade package without upgrading dependencies using pip?

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 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?

like image 554
Amy G Avatar asked May 18 '10 21:05

Amy G


People also ask

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.

Can I use pip to upgrade Python?

pip is designed to upgrade python packages and not to upgrade python itself. pip shouldn't try to upgrade python when you ask it to do so. Don't type pip install python but use an installer instead.

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


2 Answers

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.

like image 167
Mark Avatar answered Oct 17 '22 04:10

Mark


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?

like image 31
Y.H Wong Avatar answered Oct 17 '22 02:10

Y.H Wong