【问题标题】:How to properly update requests in Ubuntu 14.04如何在 Ubuntu 14.04 中正确更新请求
【发布时间】:2016-06-17 02:03:35
【问题描述】:

我目前使用的 python 包依赖于 requests 2.7.0 或更高版本,但我的系统 Ubuntu 14.04 中的 requests 是 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 手动安装,但我也担心它可能会根据它与其他包混淆

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

【问题讨论】:

  • 你能给我们你的 pip 命令吗,因为我可以做一个 mkvirtualenv foo 然后 pip install requests 没有任何问题,它会安装 requests-2.9.1-py2.py3-none-any.whl。也许你可以在 pip 之前卸载 debian 包
  • 您最初是否使用sudo 安装请求?我发现很多pip 错误是由于在某处安装了sudo 可以访问但普通用户无法访问的东西造成的。
  • 用 pip 命令编辑。 virtualenv foo 和 mkvirtualenv foo 有什么区别?
  • 试试pip install --update requests?
  • @wilbur,我认为 python-requests 是系统自带的。

标签: python ubuntu pip python-requests apt-get


【解决方案1】:

这适用于 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 版本的请求是 2.2.1,而我的是 2.0.1。您是否通过官方 python-requests .deb 包以外的其他机制手动安装了更新版本的请求?正如上面 cmets 中@wilbur 所建议的那样,您是否有可能在过去的某个时候运行过sudo pip install requests?如果是这样,可能值得运行sudo pip uninstall requests 看看您是否可以摆脱它...

【讨论】:

  • 它在 virtualenv 中工作。我在 virtualenv 中使用 pip 和 sudo,所以它使用的是系统范围的 pip,而不是 virtualenv 的。谢谢老兄。
【解决方案2】:

我需要大于 2.10.0 的 socks 代理内置支持的请求。 强制卸载 dpkg --remove --force-depends python-requests 很容易中断(即使 requests 安装了 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: 

【讨论】:

  • 这是系统范围的解决方案。如果您需要 virtualenv 一个,请参阅以前的答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多