pip build_error ai_generated partial

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

Also available as: JSON · Markdown · 中文
85%Fix Rate
88%Confidence
1Evidence
2023-05-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
pip 23.1 active
Python 3.10 active
setuptools 58.0 active

Root Cause

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

generic

中文

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

Official Documentation

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

Workarounds

  1. 75% success Apply monkey-patch in setup.py by adding 'import six' or replacing 'unicode' with 'str' in the package source before installation. Use: pip install --no-build-isolation <package> after patching.
    Apply monkey-patch in setup.py by adding 'import six' or replacing 'unicode' with 'str' in the package source before installation. Use: pip install --no-build-isolation <package> after patching.
  2. 85% success Install an older compatible version of the package that supports Python 3: pip install <package>==<last_py3_compatible_version>
    Install an older compatible version of the package that supports Python 3: pip install <package>==<last_py3_compatible_version>
  3. 70% success Build the package in a Python 2.7 environment and install the resulting wheel in Python 3. Use: python2 -m pip wheel <package> then pip install <package>.whl
    Build the package in a Python 2.7 environment and install the resulting wheel in Python 3. Use: python2 -m pip wheel <package> then pip install <package>.whl

中文步骤

  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

Dead Ends

Common approaches that don't work:

  1. 95% fail

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

  2. 90% fail

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

  3. 80% fail

    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.