diff options
Diffstat (limited to 'src/plugins/python/pythonutils.cpp')
| -rw-r--r-- | src/plugins/python/pythonutils.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/plugins/python/pythonutils.cpp b/src/plugins/python/pythonutils.cpp index fdecc5e37c..08c8750c21 100644 --- a/src/plugins/python/pythonutils.cpp +++ b/src/plugins/python/pythonutils.cpp @@ -47,18 +47,20 @@ namespace Internal { FilePath detectPython(const FilePath &documentPath) { - PythonProject *project = documentPath.isEmpty() - ? nullptr - : qobject_cast<PythonProject *>( - SessionManager::projectForFile(documentPath)); + Project *project = documentPath.isEmpty() ? nullptr + : SessionManager::projectForFile(documentPath); if (!project) - project = qobject_cast<PythonProject *>(SessionManager::startupProject()); + project = SessionManager::startupProject(); + + Environment env = Environment::systemEnvironment(); if (project) { if (auto target = project->activeTarget()) { if (auto runConfig = target->activeRunConfiguration()) { if (auto interpreter = runConfig->aspect<InterpreterAspect>()) return interpreter->currentInterpreter().command; + if (auto environmentAspect = runConfig->aspect<EnvironmentAspect>()) + env = environmentAspect->environment(); } } } @@ -72,6 +74,14 @@ FilePath detectPython(const FilePath &documentPath) if (defaultInterpreter.exists()) return defaultInterpreter; + const FilePath python3FromPath = env.searchInPath("python3"); + if (python3FromPath.exists()) + return python3FromPath; + + const FilePath pythonFromPath = env.searchInPath("python"); + if (pythonFromPath.exists()) + return pythonFromPath; + return PythonSettings::interpreters().value(0).command; } |
