Python: No such file or directory
# 💥 报错现象
Ambari 源码编译过程中,日志输出如下:
[INFO]
[INFO] --- build-helper-maven-plugin:1.8:regex-property (regex-property) @ ambari-server ---
[INFO]
[INFO] --- build-helper-maven-plugin:1.8:regex-property (full-version) @ ambari-server ---
[INFO]
[INFO] --- build-helper-maven-plugin:1.8:regex-property (regex-schema-version) @ ambari-server ---
[INFO]
[INFO] --- maven-enforcer-plugin:3.0.0-M2:enforce (enforce-maven-version) @ ambari-server ---
[INFO]
[INFO] --- maven-enforcer-plugin:3.0.0-M2:enforce (enforce-versions) @ ambari-server ---
[INFO]
[INFO] --- buildnumber-maven-plugin:1.2:create (default) @ ambari-server ---
[INFO] Checking for local modifications: skipped.
[INFO] Updating project files from SCM: skipped.
[INFO] Executing: /bin/sh -c cd /opt/modules/ambari/ambari-server && git rev-parse --verify HEAD
[INFO] Working directory: /opt/modules/ambari/ambari-server
[INFO] Storing buildNumber: 72418a7f0c267c64759057755b06677c24cc6b02 at timestamp: 1748139925310
[INFO] Executing: /bin/sh -c cd /opt/modules/ambari/ambari-server && git rev-parse --verify HEAD
[INFO] Working directory: /opt/modules/ambari/ambari-server
[INFO] Storing buildScmBranch: UNKNOWN
[INFO]
[INFO] --- maven-remote-resources-plugin:1.5:process (process-resource-bundles) @ ambari-server ---
bower jquery#1.9.1 - 3 extract archive.tar.gz
[INFO] artifact net.minidev:json-smart: checking for updates from aliyunmaven
bower jquery#1.9.1 - 3 resolved https://github.com/jquery/jquery-dist.git#3.7.1
[INFO]
[INFO] --- exec-maven-plugin:1.2.1:exec (azuredb-gen) @ ambari-server ---
/usr/bin/env: ‘python’: No such file or directory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
在 Rocky Linux 8/9 等新系统环境下,默认只安装了
python3
,而python
命令并不存在,导致部分依赖 Python 2 的构建步骤失败。
# 📋 问题分析
- Ambari 2.8.x 及部分大数据开源组件仍依赖
python
软链接(即 Python 2 兼容命令)。 - 在 Rocky Linux 8/9、CentOS 8/AlmaLinux 8+ 等新版本发行版中,仅自带
python3
,未创建python
软链接 ,直接调用python
会找不到命令。 - 相关构建插件/脚本如
exec-maven-plugin
会通过/usr/bin/env python
方式查找并调用 Python,遇到此问题即报错。
# 🛠️ 解决办法
# 1. 检查 Python 安装情况
which python
which python3
python3 --version
1
2
3
2
3
# 2. 建立 python -> python3 的软链接
如系统只存在 python3
,可用以下命令建立兼容软链:
sudo ln -s /usr/bin/python3 /usr/bin/python
1
⚠️ 注意:如果存在对 Python 2 严格依赖的脚本,建议根据实际情况测试,或安装
python2
并指定软链。
# 3. 重新执行编译命令
软链建立后,重新运行 Ambari 源码编译命令:
mvn clean install package rpm:rpm -DskipTests ...
1