How can I upgrade specific packages using pip and

2019-01-29 15:30发布

I'm using pip with a requirements file, in a virtualenv, for my Django projects. I'm trying to upgrade some packages, notably Django itself, and I'm getting an error about source code conflicts:

Source in `<virtualenv`>/build/Django has version 1.2.3 that conflicts with Django==1.2.4 (from -r requirements/apps.txt (line 3))

That's after updating the version number of Django from 1.2.3 to 1.2.4 in my requirements file. I'm using this command to actually do the upgrade:

pip --install --upgrade -E `<virtualenv dir`> --requirement `<requirements file`>

I can't find any flag that triggers a total package re-download. I even tried running an uninstall command first, then the install but no dice. Maybe I'm missing something?

7条回答
SAY GOODBYE
2楼-- · 2019-01-29 15:42

If you upgrade a package, the old one will be uninstalled.

A convenient way to do this is to use this pip-upgrader which also updates the versions in your requirements.txt file for the chosen packages (or all packages).

Installation

pip install pip-upgrader

Usage

Activate your virtualenv (important, because it will also install the new versions of upgraded packages in current virtualenv).

cd into your project directory, then run:

pip-upgrade

Advanced usage

If the requirements are placed in a non-standard location, send them as arguments:

pip-upgrade path/to/requirements.txt

If you already know what package you want to upgrade, simply send them as arguments:

pip-upgrade -p django -p celery -p dateutil

If you need to upgrade to pre-release / post-release version, add --prerelease argument to your command.

Full disclosure: i wrote this package. Hope it helps.

查看更多
萌系小妹纸
3楼-- · 2019-01-29 15:47

I'm not sure if it's exactly your problem, but in my case, I wasn't able to upgrade Django to 1.2.4 - I was always finishing with 1.2.3 version, so I uninstalled Django with:

<virtualenv>/bin/pip uninstall Django

Then I removed <virtualenv>/build/Django directory and finally I installed the proper version with:

<virtualenv>/bin/pip install Django

Hope this will help.

查看更多
女痞
4楼-- · 2019-01-29 15:52

The shortcut command for --upgrade:

pip install Django --upgrade

Is:

pip install Django -U
查看更多
虎瘦雄心在
5楼-- · 2019-01-29 15:53

If you only want to upgrade one specific package called somepackage, the command you should use in recent versions of pip is

pip install --upgrade --upgrade-strategy only-if-needed somepackage

This is very useful when you developed an application in django that currently will only work with a specific version of django (say Django=1.9.x) and want to upgrade some dependent package with a bug-fix/new feature and the upgraded package depends on django (but works with say any version of django after 1.5). The default behavior of pip install --upgrade django-some-package would be to upgrade django to the latest version available which could otherwise break your application, though with the --upgrade-strategy only-if-needed dependent packages will now only be upgraded as necessary.

查看更多
一夜七次
6楼-- · 2019-01-29 15:57

I ran the following command and it upgraded from 1.2.3 to 1.4.0

pip install Django --upgrade

Shortcut for upgrade:

pip install Django -U

Note: if the package you are upgrading has any requirements this command will additionally upgrade all the requirements to the latest versions available. In recent versions of pip, you can prevent this behavior by specifying --upgrade-strategy only-if-needed. With that flag, dependencies will not be upgraded unless the installed versions of the dependent packages no longer satisfy the requirements of the upgraded package.

查看更多
Summer. ? 凉城
7楼-- · 2019-01-29 15:59

according to pip docs example 3

pip install --upgrade django

but based on my experience, using this method will also upgrade any package related to it. example:

Assume you want to upgrade somepackage that require django >= 1.2.4 using this kind of method it will also upgrade somepackage AND django to the newest update. Just to be safe do :

# assume you want to keep django 1.2.4
pip install --upgrade somepackage django==1.2.4

Doing this will upgrade somepackage and keeping django to 1.2.4 version

查看更多
登录 后发表回答