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

使用pipenv安装scikit-learn时遇'python setup.py egg_info'错误求助

解决pipenv安装scikit-learn时的setup.py egg_info错误

问题描述

使用pipenv安装scikit-learn时持续触发以下错误,已尝试升级setuptools、pip,更换Ubuntu机器部署,问题仍存在:

Pipfile.lock (60e0f6) out of date, updating to (780331)…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
elf.repository.get_dependencies(ireq)
  File "/usr/lib/python3/dist-packages/pipenv/patched/piptools/repositories/pypi.py", line 174, in get_dependencies
    legacy_results = self.get_legacy_dependencies(ireq)
  File "/usr/lib/python3/dist-packages/pipenv/patched/piptools/repositories/pypi.py", line 222, in get_legacy_dependencies
    result = reqset._prepare_file(self.finder, ireq, ignore_requires_python=True)
  File "/usr/lib/python3/dist-packages/pipenv/patched/notpip/req/req_set.py", line 644, in _prepare_file
    abstract_dist.prep_for_dist()
  File "/usr/lib/python3/dist-packages/pipenv/patched/notpip/req/req_set.py", line 134, in prep_for_dist
    self.req_to_install.run_egg_info()
  File "/usr/lib/python3/dist-packages/pipenv/vendor/pip9/req/req_install.py", line 435, in run_egg_info
    call_subprocess(
  File "/usr/lib/python3/dist-packages/pipenv/vendor/pip9/utils/__init__.py", line 705, in call_subprocess
    raise InstallationError(
pip9.exceptions.InstallationError: Command "python setup.py egg_info" failed with error code 1 in /tmp/tmp9c38a1_hbuild/scikit-learn/

当前Pipfile内容:

[packages]
django = "==3.2.13"
asgiref = "==3.4.1"
autopep8 = "==1.6.0"
dj-database-url = "==0.5.0"
gunicorn = "==20.1.0"
pycodestyle = "==2.8.0"
pytz = "==2021.3"
sqlparse = "==0.4.2"
toml = "==0.10.2"
whitenoise = "==5.3.0"
django-environ = "==0.8.1"
mysqlclient = "*"
djangorestframework = "*"
drf-nested-routers = "*"
celery = "*"
redis = "*"
sqlalchemy = "*"
pymupdf = "*"
django-redis = "*"
pyarrow = "*"
djoser = "*"
pillow = "*"
matplotlib = "*"
seaborn = "*"
openpyxl = "*"
django-allauth = "*"
stripe = "*"
python-magic = "*"

解决方案

1. 安装Ubuntu系统层面的编译依赖

scikit-learn需要编译环境和数学库支持,先安装必要系统包:

sudo apt-get update && sudo apt-get install build-essential python3-dev python3-pip libatlas-base-dev gfortran

2. 清理pipenv缓存并重新生成依赖

旧锁文件或缓存可能导致冲突,执行以下步骤:

  • 删除旧锁文件:rm Pipfile.lock
  • 清除pipenv缓存:pipenv clean
  • 先跳过锁文件安装scikit-learn:pipenv install --skip-lock scikit-learn
  • 重新生成锁文件:pipenv lock

3. 指定scikit-learn兼容版本

当前Pipfile中大量包使用*会拉取最新版,可能和Django 3.2(支持Python 3.6-3.10)存在版本冲突。在Pipfile中添加指定版本的scikit-learn,比如兼容Python 3.6-3.10的1.0.2:

[packages]
# 保留原有包,添加以下行
scikit-learn = "==1.0.2"

之后执行pipenv install重新安装。

4. 升级pipenv到最新版本

旧版pipenv的依赖解析逻辑可能存在bug,升级后再尝试:

pip install --upgrade pipenv

5. 排查具体依赖冲突

使用pipenv自带命令检查依赖冲突,定位具体冲突包:

pipenv check

根据输出提示调整对应包的版本号。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.21 18:06:16