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

Dockerfile安装onnxruntime-extensions报错‘python: not found’求助

解决Ubuntu 20.04 Dockerfile中安装onnxruntime-extensions报错python: not found的问题

问题场景

在基于Ubuntu 20.04的Dockerfile中,从GitHub源码安装onnxruntime-extensions时,执行python -m pip install git+https://github.com/microsoft/onnxruntime-extensions.git指令,出现如下错误:

/bin/sh: 1: python: not found

问题原因

Ubuntu 20.04默认仅提供Python3环境,系统中没有python命令的软链接,只有python3及对应版本的python3.7命令。你的Dockerfile中安装了python3.7,但未建立python指向python3.7的软链接,导致系统无法识别python指令。

解决方案

提供两种可行的解决方式:

方式1:直接使用python3替代python

修改Dockerfile中的出错指令,将python替换为python3:

RUN python3 -m pip install git+https://github.com/microsoft/onnxruntime-extensions.git

同时建议统一使用pip3替代pip,避免潜在的版本冲突:

RUN pip3 install --no-cache-dir --upgrade -r requirements.txt
RUN pip3 install https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-3.4.0/en_core_web_lg-3.4.0-py3-none-any.whl

方式2:创建python到python3.7的软链接

在安装python3.7的RUN指令之后,添加一条创建软链接的命令:

RUN apt-get install -y python3.7 python3-pip python3.7-dev libc-dev build-essential zlib1g-dev libxml2-dev libxslt1-dev antiword unrtf poppler-utils \
    flac ffmpeg lame libmad0 libsox-fmt-mp3 sox libjpeg-dev swig
# 添加软链接
RUN ln -s /usr/bin/python3.7 /usr/bin/python

此后所有使用python的指令都会指向python3.7,无需修改其他命令。

额外优化建议

  • 合并多个RUN指令,减少Docker镜像层数,例如将所有apt-get install相关命令合并为一个RUN,提升构建效率。
  • 确认build-essential已安装(你的Dockerfile中已包含),该包提供了gcc等编译工具,满足onnxruntime-extensions源码编译的要求。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 04:45:41