Apline linux 安装scikit-learn 过程记录

本文记录了在Apline linux 安装scikit-learn时,踩坑填坑的过程,记录下来避免未来踩同样的坑~

基础环境

Apline linux-v3.9 x86_64

Python-3.7.12

Pip-20.2.1

Setuptools-47.1.0

Wheel-None

Numpy-1.41.6

Scipy-None

Cython-0.29.2-r0

Scikit-learn-1.0.2

STEP 01 尝试ADD安装

python 复制代码
#1.执行命令
RUN apk add py3-scikit-learn
python 复制代码
#2.报错信息
Step 10/18 : RUN apk add py3-scikit-learn
 ---> Running in 2e70b9dc74c1
fetch http://mirrors.aliyun.com/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://mirrors.aliyun.com/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
  py3-scikit-learn (missing):
    required by: world[py3-scikit-learn]
The command '/bin/sh -c apk add py3-scikit-learn' returned a non-zero code: 1
ERROR: Job failed: command terminated with exit code 1
python 复制代码
#3.报错分析
在尝试使用 Alpine Linux 的 APK 包管理器安装 py3-scikit-learn 时遇到了问题,
因为 py3-scikit-learn 这个包在 Alpine Linux 的官方仓库中并不存在。
Alpine Linux 的仓库通常只包含轻量级的基础软件包和一些常用的库,
而 scikit-learn 是一个相对复杂且依赖较多的 Python 机器学习库,
通常不包含在 Alpine 的默认仓库中。

STEP 02 尝试PIP安装

python 复制代码
#1.执行命令
RUN pip3 install scikit-learn
python 复制代码
#2.报错信息
Preparing wheel metadata: finished with status 'error'
ERROR: Command errored out with exit status 1:
  command: /usr/local/bin/python3.7 /usr/local/lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmpk1pg8fq4
    cwd: /tmp/pip-install-0h2kn6m6/scikit-learn
  Complete output (1878 lines):
  C compiler: gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC  
  compile options: '-c'
  gcc: test_program.c
  gcc objects/test_program.o -o test_program
  C compiler: gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC  
  compile options: '-c'
  extra options: '-fopenmp'
  gcc: test_program.c
  gcc objects/test_program.o -o test_program -fopenmp
  Compiling sklearn/__check_build/_check_build.pyx because it changed.
......(省略1000+行)
    /tmp/pip-build-env-t31sqbi0/overlay/lib/python3.7/site-packages/scipy/__init__.py:149:             UserWarning: A NumPy version >=1.16.5 and <1.23.0 is required for this version of SciPy (detected version 1.14.6
      UserWarning)
......(省略700+行)
ERROR: Command errored out with exit status 1: /usr/local/bin/python3.7     
   /usr/local/lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py 
   prepare_metadata_for_build_wheel /tmp/tmpk1pg8fq4 Check the logs for full command output.
   WARNING: You are using pip version 20.2.1; however, version 24.0 is available.
   You should consider upgrading via the '/usr/local/bin/python3.7 -m pip install --upgrade pip' command.
   The command '/bin/sh -c pip3 install scikit-learn' returned a non-zero code: 1
python 复制代码
#3.报错分析
scikit-learn 在准备 wheel 元数据时遇到了编译错误。
这通常发生在安装需要编译的 Python 包时,
尤其是当系统缺少必要的编译环境或依赖项时;
scikit-learn 在安装过程中正在尝试编译其 Cython 扩展模块,
这是因为它检测到了这些模块有所更改(可能是源代码更新、
Python 环境变化或依赖项版本不匹配等原因)。
然而,在编译过程中,scipy 的初始化脚本发出了一个警告,
指出当前安装的 NumPy 版本(1.14.6)不符合 scipy 的
要求(需要 >=1.16.5 且 <1.23.0 的版本)。

总结:编译阶段报错,可能原因为缺少编译依赖或依赖项版本不匹配

STEP 03 调整PIP安装依赖模块版本

python 复制代码
#1.版本调整
Pip-20.2.1
Wheel-0.42.0                 (新增)
Setuptools-47.1.0 --> 68.0.0 (升级)
Scikit-learn-1.0.2--> 0.21.2 (降级)
Python-3.7.12
Cython-0.29.2-r0  --> 3.0.11 (升级)
Numpy-1.41.6      --> 1.21.6 (降级)
Scipy-1.7.3                  (新增)
python 复制代码
#2. 执行命令
 RUN pip3 install --force-reinstall pip==20.2.1 wheel
      && pip3 install --upgrade setuptools cython    
      && pip3 install numpy scipy     
      && pip3 install scikit-learn==0.21.2

至此,Scikit-learn模块安装成功!

相关推荐
Psycho_MrZhang1 小时前
偏导数和梯度
人工智能·机器学习
虚空之月&&轮舞者2 小时前
Python与矢量网络分析仪3671E:自动化测试(Vscode)
网络·vscode·python·射频工程
李昊哲小课2 小时前
tensorflow-cpu
大数据·人工智能·python·深度学习·数据分析·tensorflow
学算法的程霖7 小时前
TGRS | FSVLM: 用于遥感农田分割的视觉语言模型
人工智能·深度学习·目标检测·机器学习·计算机视觉·自然语言处理·遥感图像分类
小彭律师7 小时前
数字化工厂中央控制室驾驶舱系统架构文档
python
old_power8 小时前
【Python】PDF文件处理(PyPDF2、borb、fitz)
python·pdf
测试开发Kevin9 小时前
从投入产出、效率、上手难易度等角度综合对比 pytest 和 unittest 框架
python·pytest
强化学习与机器人控制仿真9 小时前
Newton GPU 机器人仿真器入门教程(零)— NVIDIA、DeepMind、Disney 联合推出
开发语言·人工智能·python·stm32·深度学习·机器人·自动驾驶
hie988949 小时前
matlab稳定求解高精度二维对流扩散方程
算法·机器学习·matlab
KY_chenzhao9 小时前
用R语言+随机森林玩转遥感空间预测-基于R语言机器学习遥感数据处理与模型空间预测技术及实际项目案例分析
随机森林·机器学习·r语言·生态·遥感·空间预测