You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

安装librosa/ez_setup时遇invalid command 'egg_info'错误求助

解决pip install librosa时的egg_info命令错误

问题重现

执行pip install librosa时触发如下错误:

Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [10 lines of output]
      C:\Users\forest\AppData\Local\Temp\pip-install-9kubnarv\audioread_290887eadf0e4e15aa16d5ec304ca97a\setup.py:17: DeprecationWarning: the imp module is deprecated in favour of importlib and slated for removal in Python 3.12; see the module's documentation for alternative uses
        import imp
      D:\python\lib\site-packages\setuptools\_distutils\dist.py:265: UserWarning: Unknown distribution option: 'python_requires'
        warnings.warn(msg)
      usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
         or: setup.py --help [cmd1 cmd2 ...]
         or: setup.py --help-commands
         or: setup.py cmd --help

      error: invalid command 'egg_info'
      [end of output]

升级pip/setuptools后无效,执行pip install ez_setup也返回类似错误:

Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [10 lines of output]
      D:\python\lib\site-packages\setuptools\_distutils\dist.py:265: UserWarning: Unknown distribution option: 'zip_safe'
        warnings.warn(msg)
      D:\python\lib\site-packages\setuptools\_distutils\dist.py:265: UserWarning: Unknown distribution option: 'install_requires'
        warnings.warn(msg)
      usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
         or: setup.py --help [cmd1 cmd2 ...]
         or: setup.py --help-commands
         or: setup.py cmd --help

      error: invalid command 'egg_info'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

问题分析

核心问题是setuptools环境损坏或版本不兼容,导致无法识别egg_info命令,同时无法解析python_requires、install_requires等标准setup选项,说明当前的setuptools/distutils链路存在异常。

解决方案

1. 彻底重装pip和setuptools

这是最直接的修复方式,用Python自带的ensurepip工具重装基础工具链:

  • 先卸载现有版本:
    pip uninstall -y setuptools pip
    
  • 用ensurepip重装并升级:
    python -m ensurepip --upgrade
    

2. 强制使用wheel包安装依赖

错误源于源码包的setup.py执行失败,直接强制安装二进制wheel包可绕过该问题:

  • 先安装audioread的wheel版本:
    pip install audioread --only-binary :all:
    
  • 再安装librosa:
    pip install librosa
    

3. 使用虚拟环境隔离全局环境问题

如果全局Python环境存在配置冲突,创建独立虚拟环境:

  • 创建虚拟环境:
    python -m venv librosa_env
    
  • 激活虚拟环境:
    • Windows:
      librosa_env\Scripts\activate
      
    • Linux/macOS:
      source librosa_env/bin/activate
      
  • 在虚拟环境内执行步骤1的重装命令,再安装librosa。

4. 修复或重装Python

如果以上方法都无效,说明Python的distutils模块可能被损坏,需:

  • 下载对应版本的官方Python安装包,选择「Modify」选项,确保勾选「pip」和「setuptools」组件,执行修复安装。
  • 若修复无效,直接重装Python,安装时勾选「Add Python to PATH」。

内容的提问来源于stack exchange,提问作者forestmanna

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 18:35:28