【问题标题】:Can't uninstall project with no packages无法卸载没有包的项目
【发布时间】:2018-05-12 09:20:42
【问题描述】:

在尝试为另一个问题构建 MCVE 时,我创建了一个 example 目录,其中包含一个文件,setup.py 包含以下内容:

from setuptools import setup

setup(
    name='example',
)

并安装它

python3.6 setup.py sdist
python3.6 -m pip install --user dist/example-0.0.0.tar.gz

没有实际的包或模块,但某些东西已安装:

redacted:~/example> python3.6 -m pip list | grep example
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
example (0.0.0)

现在我无法卸载它:

redacted:~/example> python3.6 -m pip uninstall example
Can't uninstall 'example'. No files were found to uninstall.

Other posts 建议可能有一个.pth 文件我必须从我的site-packages 目录中删除,但我没有看到:

redacted:~/example> find ~/.local/lib/python3.6/site-packages/ -name '*.pth'
redacted:~/example> 

我刚刚对我的系统做了什么,我该如何撤消它?

【问题讨论】:

    标签: python pip


    【解决方案1】:

    问题中显示的步骤实际创建并安装一个真实的包。它不会创建任何可导入的文件,但会在站点包目录中创建元数据。确切的安装位置取决于您的 USER_SITE 配置,您可以通过 python3.6 -m site 进行检查,但它可能会在 ~/.local/lib/python3.6/site-packages/example-0.0.0-py3.6.egg-info

    路径文件 (.pth) 不相关。

    无法卸载的原因,说:

    无法卸载“示例”。找不到要卸载的文件。

    是因为之前执行的构建命令会在当前目录中创建一个example.egg-info,并使用python3.6 -m pipmeans the empty-string is in sys.path。因此,当前目录也被认为是一个包位置。由于当前工作目录 sys.path[0] 位于用户站点之前,因此将在此处找到 example.egg-info 元数据,而不是在站点包中。

    出于同样的原因,命令python3.6 -m pip uninstall 也首先找到此构建工件,并且没有从站点包中找到元数据,该元数据记录了应在卸载期间删除的文件。要正确卸载此软件包,您可以:

    rm -rf example.egg-info   # first prevent pip from getting confused by the temporary build artifact in cwd
    python3.6 -m pip uninstall example  # uninstall it from the user site
    

    或者,您可以在卸载之前更改目录,以便 pip 在用户站点而不是工作目录中找到 example 的包元数据。

    注意 1:pip >= 20.1 不需要这些变通方法。自 2020 年 4 月以来,使用 python -m pip 现在会从 sys.path 中弹出 cwd,它会首先从用户站点成功卸载,而不会感到困惑 (#7731)

    注意 2: 如果此 python3.6 环境中安装了 wheel,则某些细节会略有不同 - 在这种情况下,安装命令将首先从 sdist 创建一个 wheel 文件,然后安装轮子,这将导致元数据的 example-0.0.0.dist-info 子目录而不是 egg-info 子目录,但重要的细节是相同的,无论您是否安装了 .egg-info 或 .dist-info 样式用户站点。从问题中的细节无法判断python3.6环境是否有轮子安装可用。

    【讨论】:

      【解决方案2】:

      由于您没有指定任何文件,因此没有要安装的内容。所以你也不能卸载任何东西。

      【讨论】:

      • 它做了某事python3.6 -m pip list 显示 example (0.0.0) 的条目,表示已安装。
      • @user2357112 是的,但是 pip 没有找到任何文件,它可能只在某些 pip 清单中
      猜你喜欢
      • 2017-11-24
      • 1970-01-01
      • 2019-12-19
      • 2021-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-11
      • 1970-01-01
      相关资源
      最近更新 更多