【问题标题】:pip is not uninstalling packagespip 没有卸载软件包
【发布时间】:2013-01-12 10:12:30
【问题描述】:

背景

我正在开展一个学术项目,以(基本上)分析一些“谁关注谁”图表,并希望使用 Python Twitter API 包之一从 Twitter 获取一些真实数据(通过构建一些小数据集),以便测试我的一些想法。

我有点粗心,安装了两个包:

a)python-twitter0.8.2 (http://pypi.python.org/pypi/python-twitter/0.8.2)

b)twitter1.9.1 (http://pypi.python.org/pypi/twitter/1.9.1)

(a) 在 pypi 中称为python-twitter,(b) 称为twitter,所以我将这样称呼它们。

这两个都在 Python 解释器中由 import twitter 调用,但是当我写那一行时,我总是得到 twitter 一个(如果我能弄清楚如何使用 python-twitter 一个,我会能够继续,但仍会遇到相同的潜在问题)。


问题

由于我不需要 twitter 包,我决定用 pip 卸载它:

$ sudo pip uninstall twitter

给出输出:

Uninstalling twitter:
Proceed (y/n)? y
  Successfully uninstalled twitter

(实际上,我用python-twitter 尝试了同样的事情并得到了类似的响应)。

但是,当运行pip freeze 时,这两个包都显示在安装列表中!事实上,我仍然可以在解释器中成功使用import twitter 命令。很明显,这些软件包还没有被卸载。我很想知道如何卸载它们!


其他信息

我正在使用 Python 2.7 和 Ubuntu 12.04

当运行 IDLE 而不是 shell 解释器时,我键入 help('modules')twitterpython-twitter 都不会出现在列表中。在 shell 解释器中输入 help('modules') 时,我收到分段错误错误,解释器崩溃。这是错误:

>>> help('modules')

Please wait a moment while I gather a list of all available modules...

/usr/lib/python2.7/dist-packages/gobject/constants.py:24: Warning:
  g_boxed_type_register_static: assertion `g_type_from_name (name) == 0' failed
  import gobject._gobject
/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:40: Warning:
  g_boxed_type_register_static: assertion `g_type_from_name (name) == 0' failed
  from gtk import _gtk

** (python:2484): CRITICAL **: pyg_register_boxed: assertion `boxed_type != 0' failed
/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:40: Warning: cannot register
existing type `GdkDevice'
  from gtk import _gtk
/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:40: Warning: g_type_get_qdata: 
assertion `node != NULL' failed
  from gtk import _gtk
Segmentation fault (core dumped)

为什么其他问题没有为我解决这个问题:

我查看了pip freeze lists uninstalled packages 的类似帖子,但没有遇到同样的问题。

$ sudo which pip
/usr/bin/pip
$ which pip
/usr/bin/pip

这是相同的输出。此外,$ sudo pip freeze 提供与$ pip freeze 相同的输出。

非常感谢任何帮助!

【问题讨论】:

  • import twitter; print twitter.__file__ 说什么?
  • >>> print twitter.__file__ 产生:/usr/local/lib/python2.7/dist-packages/twitter/__init__.pyc

标签: shell python-2.7 pip


【解决方案1】:

对我来说,这是因为我在运行 pip freeze,这给了我与 sudo pip freeze 不同的结果。

因为我是使用sudo 卸载的,所以它没有在“非sudo”会话中卸载它。在没有sudo 的情况下卸载解决了这个问题。

【讨论】:

  • 虽然这并没有直接解决我的问题,但它确实提醒了我pip3 install不一定等同于sudo pip3 install,这间接帮助我解决了我的问题。
【解决方案2】:

在我的情况下(将 pyusb 0.4x 移动到 1.0x),使用 apt-get remove python-usb 删除旧包并通过 python setup.py 手动安装手动下载的包有效。不漂亮,但工作正常。

【讨论】:

    【解决方案3】:

    虽然 Martin 的解决方案有效,但作为一种变通方法,它并没有提供直接的答案。 您的 Ubuntu 版本 (12.04) 的 Ubuntu pip 版本是:

     python-pip (1.0-1build1)
    

    这也是 Debian Wheezy 的相同版本。此版本有一个奇怪的错误,导致无法删除软件包。
    如果您使用脚本get-pip.py 从上游获取 pip,您将拥有一个可以删除 pacakges 的固定版本的 pip(截至现在 v. 1.5.6)。

    更新

    Python 的 pip 确实是一个快速移动的目标。所以使用 Debian 或 Ubuntu 的 pip 肯定会有 bug。 不要使用那些发行版的pip。 而是从上游安装 pip。

    如果您想将 pip 安装的包注册为系统包,我强烈建议您也使用stdeb

    【讨论】:

    【解决方案4】:

    我在升级软件包时遇到了困难,因为 pip 无法成功卸载它。我不得不删除 .egg-info 和 /usr/lib/python2.7/dist-packages 中的文件夹,然后我尝试使用 --upgrade 进行安装,它成功了。

    【讨论】:

      【解决方案5】:

      您可以随时手动删除包;你可以运行:

      sudo rm -rf /usr/local/lib/python2.7/dist-packages/twitter
      

      从您的dist-packages 目录中删除该软件包。您可能需要编辑同一目录中的easy-install.pth 文件并从中删除twitter 条目。

      【讨论】:

      • 谢谢!我还应该删除twitter-1.9.1-py2.7.egg-infotwitter.pytwitter.pyc 还是删除目录就足够了?
      • 是的,删除所有这些;和python-twitter egg 信息(如果有)。从easy-install.pth 文件中删除twitterpython-twitter(如果有的话,用grep 查找任何其他.pth 文件中的名称)。
      • 是的。这只是发生在我身上。有谁知道这是什么原因造成的?
      • @BrettWidmeier,问题的原因是在 pip 的 debian 版本中进行了一些修改,这也是 ubuntu 包的来源。请参阅下面的答案。
      • @DannyStaple:您的 Python 的位置将根据您安装 Python 的方式和您的发行版而有所不同。使用python -m site 让Python 告诉你它在哪里寻找包(在sys.path 列表中查找site-packages 条目)。
      猜你喜欢
      • 2018-11-08
      • 1970-01-01
      • 1970-01-01
      • 2016-03-02
      • 2021-11-16
      • 2018-07-27
      • 2015-08-23
      • 2012-07-28
      • 2020-05-23
      相关资源
      最近更新 更多