pip build_error ai_generated partial

错误:子进程以错误退出:python setup.py egg_info 未成功运行。 退出代码:1 __main__.NameError: 名称 'unicode' 未定义

error: subprocess-exited-with-error: python setup.py egg_info did not run successfully. exit code: 1 __main__.NameError: name 'unicode' is not defined

ID: pip/egg-info-failure-setup-py-encoding

其他格式: JSON · Markdown 中文 · English
85%修复率
88%置信度
1证据数
2023-05-15首次发现

版本兼容性

版本状态引入弃用备注
pip 23.1 active
Python 3.10 active
setuptools 58.0 active

根因分析

包的 setup.py 使用了 Python 2 风格的 'unicode' 内置函数,该函数在 Python 3 中被移除,导致 egg_info 生成失败。

English

Package's setup.py uses Python 2 style 'unicode' built-in, which was removed in Python 3, causing egg_info generation to fail.

generic

官方文档

https://pip.pypa.io/en/stable/topics/dependency-resolution/#build-failures

解决方案

  1. 在 setup.py 中应用猴子补丁,添加 'import six' 或将 'unicode' 替换为 'str',然后使用 pip install --no-build-isolation <package> 安装。
  2. 安装支持 Python 3 的旧版本包:pip install <package>==<last_py3_compatible_version>
  3. 在 Python 2.7 环境中构建包并安装生成的 wheel:python2 -m pip wheel <package> 然后 pip install <package>.whl

无效尝试

常见但无效的做法:

  1. 95% 失败

    Running pip install --no-cache-dir does not fix the root cause; the setup.py is still broken.

  2. 90% 失败

    Upgrading pip alone does not patch the package's broken setup.py; the NameError persists.

  3. 80% 失败

    Using --use-pep517 may switch to a different build system, but if the package lacks pyproject.toml, it falls back to setup.py and fails again.