如何在 Ubuntu 14.04 中正确更新请求

How to properly update requests in Ubuntu 14.04

我目前使用的 python 包依赖于请求 2.7.0 或更高版本,但我的系统 Ubuntu 14.04 中的请求是版本 2.2.1。我尝试通过 pip 升级:

 pip install requests==2.7.0

但它给了我一个错误,说:

Not uninstalling requests at /usr/lib/python2.7/dist-packages, owned by OS

我尝试使用 apt-get install --only-upgrade python-requests 对其进行升级,但它说它已经是最新版本(实际上不是)。

然后我尝试在虚拟环境中安装,但它给出的消息与上面的 pip 消息相同。

最后想到了两个方案:

1-) 通过 apt-get 卸载然后通过 pip 安装 - 我认为这太冒险了,因为它会卸载很多其他包。

2-) 从 github 克隆并通过 setup.py 手动安装,但我也担心它可能会与依赖它的其他软件包混淆

最好的方法是什么?我缺少一些简单的东西吗?

这适用于 Ubuntu 14.04:

~ › sudo apt-get install -u python-requests
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-requests is already the newest version.
python-requests set to manually installed.
0 to upgrade, 0 to newly install, 0 to remove and 15 not to upgrade.

~ › python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.__version__
'2.0.1'
>>> 

~ › mkvirtualenv test
New python executable in test/bin/python
Installing setuptools, pip, wheel...done.

~ (test) › pip install requests
Collecting requests
  Using cached requests-2.9.1-py2.py3-none-any.whl
Installing collected packages: requests
Successfully installed requests-2.9.1

~ (test) › python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.__version__
'2.9.1'
>>> 

我想知道为什么你的 OS/Ubuntu 版本的 requests 是 2.2.1,而我的是 2.0.1。您是否通过官方 python-requests .deb 包之外的其他机制手动安装了更新版本的请求?正如@wilbur 在上面的评论中所建议的那样,你是否有可能在过去的某个时候有 运行 sudo pip install requests ?如果是这样,可能值得 运行宁 sudo pip uninstall requests 看看你是否可以摆脱它...

我需要请求 >2.10.0 以获得 socks 代理内置支持。 强制卸载 dpkg --remove --force-depends python-requests 中断 apt(即使请求已安装 pip)。

apt-get install python-requests 将其回滚到 2.2.1,这是 trusty 存储库中的最高版本。 然而,yakkety ubuntu repo 包含 2.10.0 python-requests,根据需要,所以我做了以下操作:

 apt-add-repository "deb http://us.archive.ubuntu.com/ubuntu/ yakkety main"
 apt-get update
 apt-get install python-requests # it installs 2.10.0
 apt-add-repository -r "deb http://us.archive.ubuntu.com/ubuntu/ yakkety main"
 apt-get update

注意! 必须执行第二个 apt-get update 以删除 yakkety 索引,以免 apt-get upgrade 偶尔执行并破坏您的系统。

所以现在我有了所需的版本。

$ sudo pip2 show requests
    ---
    Name: requests
    Version: 2.10.0
    Location: /usr/lib/python2.7/dist-packages
    Requires: