PySide2 application failed to start

2019-04-12 00:14发布

问题:

I just tried to test the newly released version of PySide2 (5.11) on Windows 10, 64 bit version. But the "Hello World" example does not work. I am using Python 3.6 with PyCharm. The interpreter I use is from Anaconda. So I pip installed the PySide2 version and also tried to install via "conda install ..." the older version of PySide2. Both installations worked, but I get the same error message for both libraries.

The error message is popping up in a separate screen saying: "This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. Available platform plugins are: minimal, offscreen, windows."

So I definitely can see the plugin files in the correct folder. I tried reinstalling. Deleted everything and tried other IDEs. But nothing solved the problem.

Any help is appreciated.

回答1:

If you run the app after having set QT_DEBUG_PLUGINS=1, you should get more info on what is the issue. In my case, I was getting:

QFactoryLoader::QFactoryLoader() checking directory path "C:/Users/xxxxx/AppData/Local/py3/platforms" ... qt.qpa.plugin: Could not find the Qt platform plugin "windows" in ""

Such a folder does not exist on my machine.

There are a few tickets somehow related to a similar issue (not sure it is the same problem):

  • https://bugreports.qt.io/browse/PYSIDE-559
  • https://github.com/pyside/pyside2-setup/issues/57
  • https://github.com/conda-forge/matplotlib-feedstock/issues/2
  • https://github.com/conda-forge/qt-feedstock/issues/71

My current working solution is to remove PyQt, qt and sip anaconda packages, then to manually delete a relic qt.conf in the root folder of the environment. After that, the official PyPi PySide2 wheel works fine.



回答2:

Try This :

import sys,os
import PySide2

dirname = os.path.dirname(PySide2.__file__)
plugin_path = os.path.join(dirname, 'plugins', 'platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path

# code ....... 
# .......