From d4cfa4fd4496735ea45afcd2b0cfb3607cadd1c9 Mon Sep 17 00:00:00 2001 From: yinrun Date: Thu, 17 Oct 2024 18:47:40 +0800 Subject: [PATCH] Find Python3 in default env PATH for ACPO Enable the use of user python version, avoid the wrong version of python without AI infra. --- llvm/lib/Analysis/ACPOMLInterface.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Analysis/ACPOMLInterface.cpp b/llvm/lib/Analysis/ACPOMLInterface.cpp index f48eb46638e3..7d84bd5112d6 100644 --- a/llvm/lib/Analysis/ACPOMLInterface.cpp +++ b/llvm/lib/Analysis/ACPOMLInterface.cpp @@ -146,7 +146,15 @@ ACPOMLPythonInterface::ACPOMLPythonInterface() : NextID{0} { } int32_t PID = (int32_t) llvm::sys::Process::getProcessId(); - std::string ExecPython = "/usr/bin/python3"; + std::string ExecPython; + llvm::ErrorOr Res = llvm::sys::findProgramByName("python3"); + if (std::error_code EC = Res.getError()) { + LLVM_DEBUG(dbgs() << "python3 could not be found, error_code " << EC.value() << "\n"); + return; + } else { + ExecPython = Res.get(); + LLVM_DEBUG(dbgs() << "python3 version found in " << ExecPython << "\n"); + } std::string PythonScript = *Env + "/" + std::string(ACPO_ML_PYTHON_INTERFACE_PY); std::string PIDStr = std::to_string(PID); -- Gitee