diff options
author | Adrian Herrmann <adrian.herrmann@qt.io> | 2023-02-07 17:04:54 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-02-14 13:08:24 +0000 |
commit | d78c03e058950a7948b8d6271ab8991cdb65f186 (patch) | |
tree | 5827c65f68ebbcaaf97fb4d1bd315c75a2237502 | |
parent | 34791c75be1e34c1f7118b0ef38a09d9a113e97b (diff) |
Fix broken Qt prefix for conda installs
If PySide6 is installed through Anaconda, it will conflict with
Anaconda's own Qt package, which is based on Qt 5, creating a version
mismatch. To work around this, if PySide runs in a conda env, register
an internal qt.conf setting the prefix value to the corresponding path
in site-packages.
Change-Id: I5639d7eeaf524a8a4aa533dc5a83bdb0c74cbd9f
Reviewed-by: Christian Tismer <tismer@stackless.com>
(cherry picked from commit 06e7cb7d61e6ef7bbd073b85cbf8d5e324e242c6)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | sources/pyside6/doc/quickstart.rst | 7 | ||||
-rw-r--r-- | sources/pyside6/libpyside/pyside.cpp | 10 | ||||
-rw-r--r-- | sources/pyside6/libpyside/pysideinit.h | 3 |
3 files changed, 19 insertions, 1 deletions
diff --git a/sources/pyside6/doc/quickstart.rst b/sources/pyside6/doc/quickstart.rst index 141edf94c..baf4e1c16 100644 --- a/sources/pyside6/doc/quickstart.rst +++ b/sources/pyside6/doc/quickstart.rst @@ -56,6 +56,13 @@ Installation pip install --index-url=https://download.qt.io/snapshots/ci/pyside/6.0.0/latest pyside6 --trusted-host download.qt.io + .. note:: Starting with 6.4.3, PySide6 can be used from inside a conda + environment, but any manual changes you make to the qt.conf file will be + ignored. If you want to set custom values to the Qt configuration, set + them in a qt6.conf file instead. Read more about `qt.conf`_. + +.. _`qt.conf`: https://doc.qt.io/qt-6/qt-conf.html + * **Test your installation** Now that you have |project| installed, test your setup by running the following Python diff --git a/sources/pyside6/libpyside/pyside.cpp b/sources/pyside6/libpyside/pyside.cpp index 84266e28b..06a6b2e70 100644 --- a/sources/pyside6/libpyside/pyside.cpp +++ b/sources/pyside6/libpyside/pyside.cpp @@ -840,12 +840,20 @@ bool registerInternalQtConf() maybeQtConfPath = QDir::toNativeSeparators(maybeQtConfPath); bool executableQtConfAvailable = QFileInfo::exists(maybeQtConfPath); + QString maybeQt6ConfPath = QDir(appDirPath).filePath(u"qt6.conf"_s); + maybeQt6ConfPath = QDir::toNativeSeparators(maybeQt6ConfPath); + bool executableQt6ConfAvailable = QFileInfo::exists(maybeQt6ConfPath); + // Allow disabling the usage of the internal qt.conf. This is necessary for tests to work, // because tests are executed before the package is installed, and thus the Prefix specified // in qt.conf would point to a not yet existing location. bool disableInternalQtConf = qEnvironmentVariableIntValue("PYSIDE_DISABLE_INTERNAL_QT_CONF") > 0; - if (disableInternalQtConf || executableQtConfAvailable) { + bool runsInConda = + qEnvironmentVariableIsSet("CONDA_DEFAULT_ENV") || qEnvironmentVariableIsSet("CONDA_PREFIX"); + + if (!runsInConda && (disableInternalQtConf || executableQtConfAvailable) || + runsInConda && executableQt6ConfAvailable) { registrationAttempted = true; return false; } diff --git a/sources/pyside6/libpyside/pysideinit.h b/sources/pyside6/libpyside/pysideinit.h index 3a8f20158..c623a0d27 100644 --- a/sources/pyside6/libpyside/pysideinit.h +++ b/sources/pyside6/libpyside/pysideinit.h @@ -17,6 +17,9 @@ PYSIDE_API void init(PyObject *module); /// /// This is used in a standalone build, to inform QLibraryInfo of the Qt prefix /// (where Qt libraries are installed) so that plugins can be successfully loaded. +/// +/// This is also used if PySide runs from inside a conda environment to solve +/// conflicts with the qt.conf installed by Anaconda Qt packages. PYSIDE_API bool registerInternalQtConf(); } //namespace PySide |