pip refuses to upgrade

2019-02-25 07:38发布

I currently have installed pip 8.1.2.

So I want to upgrade it to the latest version (9.0.1) and I execute:

sudo pip install --upgrade pip


Collecting pip
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 846kB/s 
Installing collected packages: pip
  Found existing installation: pip 8.1.2
    Not uninstalling pip at /usr/lib/python2.7/dist-packages, outside environment /usr
Successfully installed pip-8.1.2
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

It seems that it correctly downloads 9.0.1 but then it refuses to uninstall the existing installation (8.1.2)

And then at the end it suggests me to upgrade using the same exact instruction I already provided!

Am I doing anything wrong?

3条回答
戒情不戒烟
2楼-- · 2019-02-25 08:02

The Ubuntu pip version has been patched to prevent self-upgrades (all installation into system-managed files are prevented, the patch is named hands-off-system-packages.patch). You are supposed to use the Ubuntu packaging system to upgrade instead. The feedback provided could be improved certainly.

As there is no Ubunutu package of pip 9.0.1 available yet for your Ubuntu version, you can't actually upgrade to a newer version this way (there is a version for Zesty however).

A (ugly) work-around is to use easy_install instead:

sudo easy_install -U pip

This works because easy_install has not been booby-trapped to prevent the upgrade. However, this'll replace system managed files with the newer pip version. If your package manager were to re-install the python-pip package, it'll happily overwrite those files and you could in theory end up with a broken installation. Also, easy_install adds more files than the package would, and those extra files could cause issues later down the line, especially when you upgrade python-pip later when a new version is packaged.

If you were to use a virtualenv, you are free to upgrade pip inside that, which works just fine.

查看更多
趁早两清
3楼-- · 2019-02-25 08:23

If above are not working, please try this it works(I had similar situations and this works):

  1. download get-pip.py: curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
  2. Run the downloaded file: python get-pip.py

    Above uninstalls the old version and install the latest ones. Reference Link: https://pip.pypa.io/en/stable/installing/#installing-with-get-pip-py

查看更多
兄弟一词,经得起流年.
4楼-- · 2019-02-25 08:23

Had a similar issue with pip not wishing to upgrade, though I'm not keen on replacing the package manager's version and as I'm always adding the --user option on installations via pip I figured "what's the harm?" in doing the same with pip on itself.

pip install --user --upgrade pip

It'll only work for one user but for some use cases that is just peachy.

查看更多
登录 后发表回答