5

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.

Christian Sirolli
  • 246
  • 1
  • 6
  • 18

3 Answers3

11

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 ....... 
# .......
Alaa Aqeel
  • 615
  • 8
  • 16
  • 1
    Usually it's better to explain a solution instead of just posting some rows of anonymous code. You can read [How do I write a good answer](https://stackoverflow.com/help/how-to-answer), and also [Explaining entirely code-based answers](https://meta.stackexchange.com/questions/114762/explaining-entirely-%E2%80%8C%E2%80%8Bcode-based-answers) – Anh Pham Nov 10 '18 at 08:42
  • For PySide2 2020, `plugin_path = os.path.join(dirname, 'Qt', 'plugins', 'platforms')` works well. – Color Sep 18 '20 at 04:09
6

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):

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.

gmas80
  • 1,218
  • 1
  • 14
  • 44
  • Thank you for your answer, but it does not resolve the problem. I tried debugging and noticed that the Pyside2 __init__ file fails to import QtNetwork. This happens in the _setupQtDirectories function. The code line throwing an exception is: from . import QtNetwork Might this be the source of the problem? – baby_chewbacca Jul 30 '18 at 09:54
  • Do you have the conda Qt package installed? If yes, read this: https://github.com/conda-forge/qt-feedstock/issues/70 and https://bugreports.qt.io/browse/PYSIDE-761 – gmas80 Jul 30 '18 at 14:24
  • Thanks, it is working now! I removed the Qt package, which came with anaconda and installed pyside2. – baby_chewbacca Aug 01 '18 at 21:07
  • Great! I edited my answer with my working solution based on feedback that I got after opening the tickets. – gmas80 Aug 02 '18 at 00:26
  • After setting set QT_DEBUG_PLUGINS=1, debug log disclosed QFactoryLoader::QFactoryLoader() checking directory path at "C:/program files/python37/lib/site-packages/PyQt4/plugins/platforms" and "C:/Program Files/Python37/platforms". I copied qwindows.dll from C:\Program Files\Python37\Lib\site-packages\PySide2\plugins\platforms to C:\Program Files\Python37\Lib\site-packages\PyQt4\plugins\platforms and it worked on Windows7. Had no other Qt instance installed. – Ajay Mar 25 '19 at 18:52
0

check whether you have this directory or not: C:\Users\your_user_name\anaconda3\envs\your_virtual_env_name\Library\plugins.

If you don't have it, copy the whole "plugin" folder from your PySide2 site-package.
Mine is in here: C:\Users\your_user_name\anaconda3\envs\your_virtual_env_name\Lib\site-packages\PySide2\plugins

and paste the whole folder to C:\Users\your_user_name\anaconda3\envs\your_virtual_env_name\Library

S.B
  • 13,077
  • 10
  • 22
  • 49
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 07 '22 at 11:14