summaryrefslogtreecommitdiff
path: root/src/plugins/python/pythonutils.cpp
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2022-06-09 15:29:11 +0200
committerDavid Schulz <david.schulz@qt.io>2022-06-15 05:44:46 +0000
commit2b428d5de09659220b7b94d793fdce401ed9d2bf (patch)
tree5ebde3cd0f76b08aabd32dca07a2c427f83ded91 /src/plugins/python/pythonutils.cpp
parent02bfd03c226a15d2ed90ca43580df7e099e310a6 (diff)
downloadqt-creator-2b428d5de09659220b7b94d793fdce401ed9d2bf.tar.gz
Python: prefer python from path when detecting python for document
Change-Id: I794a741fa7257833f0b4efbc25dfae43b8748427 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/python/pythonutils.cpp')
-rw-r--r--src/plugins/python/pythonutils.cpp20
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;
}