开发者
毕昇编译器Autotuner 安装问题修复记录
毕昇编译器Autotuner 安装问题修复记录
原创
发表于05/22
4160

Autotuner 安装问题修复记录

服务器信息

  • 服务器:华为云ECS
  • 用户:root
  • 架构:aarch64
  • 系统:openEuler 22.03 LTS
  • BiSheng Compiler 路径:/opt/compiler/BiShengCompiler-5.1.0.2-aarch64-linux

问题现象

服务器上已经存在 BiSheng Compiler 和 Autotuner 启动脚本:

/opt/compiler/BiShengCompiler-5.1.0.2-aarch64-linux/bin/install-autotuner.sh
/opt/compiler/BiShengCompiler-5.1.0.2-aarch64-linux/bin/llvm-autotune
/opt/compiler/BiShengCompiler-5.1.0.2-aarch64-linux/bin/auto-tuner

但配置 PATH 后执行 Autotuner 报错:

bad magic number in 'autotuner': b'\xa7\r\r\n'

初始检查结果:

uname -m
# aarch64

cat /etc/os-release
# NAME="openEuler"
# VERSION="22.03 LTS"

python3 -V
# Python 3.9.9

python3.11 -V
# bash: python3.11: command not found

根因

Autotuner 的 Python 字节码与当前解释器版本不匹配。

**服务器默认 **python33.9.9,而 Autotuner 包内的字节码需要更高版本 Python。执行 llvm-autotune -h 时,启动脚本使用的是:

#!/usr/bin/env python3

**因此它会加载当前 PATH 中的 **python3。当 python3 指向系统自带的 Python 3.9.9 时,就会触发 bad magic number

修复思路

**不替换系统 **/usr/bin/python3,避免影响 openEuler 自带工具和系统包管理器。

采用独立 Python 安装路径:

/opt/python-3.11.9

再让 root 用户的 shell PATH 优先使用:

/opt/python-3.11.9/bin
/opt/compiler/BiShengCompiler-5.1.0.2-aarch64-linux/bin

修复步骤

1. 检查系统仓库

dnf list --available "python3.11*" || true
dnf list --available "python3.10*" "python310*" "python3.12*" || true

**结果:openEuler 当前仓库没有可直接安装的 **python3.10python3.11 包。

2. 补齐 Python 编译依赖

dnf install -y \
  gcc gcc-c++ make \
  openssl-devel bzip2-devel libffi-devel zlib-devel \
  sqlite-devel readline-devel xz-devel ncurses-devel

其中大部分依赖已存在,新增安装了:

gcc-c++
libffi-devel
libstdc++-devel

3. 编译安装 Python 3.11.9

PYVER=3.11.9
PREFIX=/opt/python-$PYVER
SRC=/usr/local/src

mkdir -p "$SRC"
cd "$SRC"

curl -fL -o "Python-$PYVER.tgz" \
  "https://www.python.org/ftp/python/$PYVER/Python-$PYVER.tgz"

rm -rf "Python-$PYVER"
tar -xzf "Python-$PYVER.tgz"
cd "Python-$PYVER"

./configure --prefix="$PREFIX" --with-ensurepip=install
make -j"$(nproc)"
make altinstall
```

**验证:**

```
/opt/python-3.11.9/bin/python3.11 -V
# Python 3.11.9

/opt/python-3.11.9/bin/python3.11 -m pip --version
# pip 24.0 from /opt/python-3.11.9/lib/python3.11/site-packages/pip
```

### 4. 给独立 Python 增加 python3 入口

`install-autotuner.sh` 和 Autotuner 启动脚本都依赖 `python3`,所以在独立 Python 目录内增加安全的软链接:

```
ln -sf /opt/python-3.11.9/bin/python3.11 /opt/python-3.11.9/bin/python3
```

**注意:没有修改 **`/usr/bin/python3`。

### 5. 使用 Python 3.11 重新安装 Autotuner

**官方安装脚本第一次执行时,从 **`files.pythonhosted.org` 下载依赖超时。因此改用国内 PyPI 镜像手工执行等价安装:

```
PY_PREFIX=/opt/python-3.11.9
COMPILER=/opt/compiler/BiShengCompiler-5.1.0.2-aarch64-linux

export PATH="$PY_PREFIX/bin:$COMPILER/bin:$PATH"
export PIP_PROGRESS_BAR=off
export PIP_NO_COLOR=1

python3 -m pip install --user --force-reinstall --timeout 180 --retries 10 \
  -i https://pypi.tuna.tsinghua.edu.cn/simple \
  "$COMPILER/lib/autotuner/huawei_opentuner-0.8.8-py3-none-any.whl" \
  "$COMPILER/lib/autotuner/autotuner-2.2.0-py3-none-any.whl"

安装结果:

Successfully installed SQLAlchemy-1.4.49 autotuner-2.2.0 certifi-2026.5.20
charset_normalizer-3.4.7 configparser-7.2.0 defusedxml-0.7.1 dill-0.4.1
future-1.0.0 greenlet-3.5.1 huawei-opentuner-0.8.8 idna-3.15
numpy-1.23.5 pyyaml-6.0.3 requests-2.34.2 urllib3-2.7.0

Autotuner 安装位置:

/root/.local/lib/python3.11/site-packages

6. 固化 root 用户环境变量

**检查到 **/root/.bash_profile 会加载 /root/.bashrc,因此将环境写入 /root/.bashrc

cat >> /root/.bashrc <<'EOF'

# BiSheng Autotuner environment
export PATH=/opt/python-3.11.9/bin:/opt/compiler/BiShengCompiler-5.1.0.2-aarch64-linux/bin:$PATH
EOF
```

## 修复后验证

**使用新登录 shell 验证:**

```
bash -lc 'echo "python=$(python3 -V 2>&1)"; echo "python_path=$(command -v python3)"; echo "llvm_path=$(command -v llvm-autotune)"; llvm-autotune -h >/dev/null && auto-tuner -h >/dev/null && echo autotuner_ok'

输出:

python=Python 3.11.9
python_path=/opt/python-3.11.9/bin/python3
llvm_path=/opt/compiler/BiShengCompiler-5.1.0.2-aarch64-linux/bin/llvm-autotune
autotuner_ok

手工验证:

llvm-autotune -h
auto-tuner -h

**两个命令均可正常输出帮助信息,原来的 **bad magic number in 'autotuner' 已消失。

回滚方式

**如需回滚本次修复,执行前请确认没有其他业务依赖 **/opt/python-3.11.9

# 1. 删除 /root/.bashrc 中的 BiSheng Autotuner environment 块
vi /root/.bashrc

# 2. 删除独立 Python
rm -rf /opt/python-3.11.9

# 3. 删除 Python 3.11 用户站点中的 Autotuner 包
rm -rf /root/.local/lib/python3.11

**不需要恢复 **/usr/bin/python3,因为修复过程中没有修改它。

收藏举报
Level 1
0
帖子
0
粉丝
0
获赞