首页 > 解决方案 > 如何在 gem5 中同时使用 python 2.7 和 3?

问题描述

我有一台机器有两个 gem5-repository 实例:一个我保持最新,另一个使用我还不能更新的旧版本。

我使用的是 Ubuntu 16.04,目前的 gem5 版本已经弃用了 python 2.7。我推迟了升级我的操作系统,并使用了一些解决方法(恢复提交scons: Set the minimum scons version to 3.0,并手动添加EM_RISCVsrc/base/loader/elf_object.cc);然而,最近事情变得一团糟,所以我不得不这样做以使用 SCons 3 和 python3。

在尝试了 Ubuntu 18.04 和 20.04 之后,由于在某些 python 类中使用了元类,我仍然无法编译。

不过,真正的问题很清楚。即使我安装了python3(在/usr/bin/),也找不到python3-config:

Info: Using Python config: python2.7-config

如何在同一台机器上同时使用 python 2.7 和 3 来编译不同版本的 gem5?

标签: pythongem5

解决方案


如果 SCons 找不到 python3-config,请使用其位置手动覆盖 PYTHON_CONFIG,并设置适当的环境。

alias scons2="/usr/bin/env python2.7 $(which scons) PYTHON_CONFIG=$(which python2.7-config)"
alias scons3="/usr/bin/env python3 $(which scons) PYTHON_CONFIG=$(which python3-config)"

然后,编译更新的存储库:

scons3 -j5 ./build/ARM/gem5.opt

要编译需要 python 2.7 的版本:

scons2 -j5 ./build/ARM/gem5.opt

推荐阅读