PySide2的This application failed to start because no Qt platform plugin could be initialized解决方式

解决PySide2的This application failed to start because no Qt platform plugin could be initialized问题

Today, when installed pyside2 of mentality can be described as very hard, but fortunately finally resolved.

The first is when the pip install has been retrying question, there occurs simultaneously with the win10 manually set the proxy has been opened, after a series of search solutions to no avail, and finally I would like to use it as a proxy before ssr no effect delete, delete a series of pre-set may have some influence on this, and then download back, get an agent after pip completely ok.

After the error occurred when the title is written pyside2 be gui programming window, the same search after a series of torture, and finally kept Tucao among domestic blog and turn the original can not find a few answers, finally search the next stackoverflow, and then solved.

To summarize ideas: domestic blog is usually modify environment variables, this point is not in question, but because of domestic blog is written mostly pyqt instead pyside2, so configure the environment variables differ.

In fact, the solution to the problem is to configure the environment variables, but the path can not just be written plugin, and the platform should also join in, of course, can also be added to the code each time the program to continue your own code:

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

If you want to once and for all, then play more than a print look pyside2 installation directory:

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
print(plugin_path)

The path of the output obtained copy it (second row):

And then configure the environment variable click on it:

However, it is possible to configure the environment does not work, then there is a fundamental way possible, that is to change the package root directory of the __init__ file, before the comment plus the above string of code can (take note PySide2 removed):

Guess you like

Origin www.cnblogs.com/IaCorse/p/12024428.html