diff --git a/src/plugins/python/pipsupport.cpp b/src/plugins/python/pipsupport.cpp index dd213248961..1ece0c534ca 100644 --- a/src/plugins/python/pipsupport.cpp +++ b/src/plugins/python/pipsupport.cpp @@ -5,6 +5,7 @@ #include "pythonplugin.h" #include "pythontr.h" +#include "pythonutils.h" #include #include @@ -80,10 +81,12 @@ void PipInstallTask::run() } } - if (!m_targetPath.isEmpty()) - arguments << "-t" << m_targetPath.toString(); - else if (!QDir(m_python.parentDir().toString()).exists("activate")) + if (!m_targetPath.isEmpty()) { + QTC_ASSERT(m_targetPath.isSameDevice(m_python), emit finished(false); return); + arguments << "-t" << m_targetPath.path(); + } else if (!isVenvPython(m_python)) { arguments << "--user"; // add --user to global pythons, but skip it for venv pythons + } m_process.setCommand({m_python, arguments}); m_process.setTerminalMode(TerminalMode::Run); diff --git a/src/plugins/python/pythonlanguageclient.cpp b/src/plugins/python/pythonlanguageclient.cpp index a6bb9fcaa81..5a54a8c4b64 100644 --- a/src/plugins/python/pythonlanguageclient.cpp +++ b/src/plugins/python/pythonlanguageclient.cpp @@ -74,12 +74,12 @@ static QHash &pythonClients() static FilePath pyLspPath(const FilePath &python) { - if (python.needsDevice()) - return {}; const QString version = pythonVersion(python); - if (version.isEmpty()) - return {}; - return Core::ICore::userResourcePath("pylsp") / FileUtils::fileSystemFriendlyName(version); + if (!python.needsDevice()) + return Core::ICore::userResourcePath() / "pylsp" / version; + if (const expected_str tmpDir = python.tmpDir()) + return *tmpDir / "qc-pylsp" / version; + return {}; } static PythonLanguageServerState checkPythonLanguageServer(const FilePath &python) @@ -113,20 +113,22 @@ public: protected: void startImpl() override { - if (!m_cmd.executable().needsDevice()) { + const FilePath python = m_cmd.executable(); + Environment env = python.deviceEnvironment(); + const FilePath lspPath = pyLspPath(python); + if (!lspPath.isEmpty() && lspPath.exists() && QTC_GUARD(lspPath.isSameDevice(python))) { + env.appendOrSet("PYTHONPATH", + lspPath.path(), + OsSpecificAspects::pathListSeparator(env.osType())); + } + if (!python.needsDevice()) { // todo check where to put this tempdir in remote setups - Environment env = Environment::systemEnvironment(); env.appendOrSet("PYTHONPATH", m_extraPythonPath.path().toString(), OsSpecificAspects::pathListSeparator(env.osType())); - const FilePath lspPath = pyLspPath(m_cmd.executable()); - if (!lspPath.isEmpty() && lspPath.exists()) { - env.appendOrSet("PYTHONPATH", - pyLspPath(m_cmd.executable()).toString(), - OsSpecificAspects::pathListSeparator(env.osType())); - } - setEnvironment(env); } + if (env.hasChanges()) + setEnvironment(env); StdIOClientInterface::startImpl(); } };