Skip to content

Instantly share code, notes, and snippets.

@mchapman87501
Created October 7, 2021 13:23
Show Gist options
  • Save mchapman87501/eee8b357647e540254e286ad7eb4df38 to your computer and use it in GitHub Desktop.
Save mchapman87501/eee8b357647e540254e286ad7eb4df38 to your computer and use it in GitHub Desktop.
PySide6 vs. pyqt: Finding Qt Plugins
import os
from pathlib import Path
import sys
import sysconfig
from PySide6.QtCore import QCoreApplication
from PySide6.QtWidgets import QApplication
from .main_win import MainWin
def main() -> int:
# If you're trying to install a wheel that depends on PySide6
# in a conda environment that already has conda's pyqt, the
# wheel's code may crash when instantiating QApplication:
# Found invalid metadata in lib \
# /path/to/conda/env/plugins/platforms/libqcocoa.dylib: \
# Invalid metadata version
#
# A workaround: before instantiating QApplication, set QT_PLUGIN_PATH
# to point to the PySide6 package in the currently running Python:
site_pkgs = Path(sysconfig.get_path("platlib"))
ps6_qt_plugins = site_pkgs / "PySide6" / "Qt" / "plugins"
if ps6_qt_plugins.is_dir() and ("QT_PLUGIN_PATH" not in os.environ):
os.environ["QT_PLUGIN_PATH"] = os.fspath(ps6_qt_plugins)
app = QApplication(sys.argv)
mainWin = MainWin()
mainWin.show()
return app.exec()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment