I am working on a python application based on PyQt5. Everything was running good until I redo my PC and reinstall windows again because of some issue. I had copied my environment and after reinstalling Anaconda, I copied that environment again in env folder. Now the problem is that, when I run my code in PyCharm IDE, it displays and error dialog like this:
I have tried multiple solutions such as:
Solution 1: Change the QT Files Location
Sometimes, a simple trick such as changing the QT files location is enough to get rid of the error. Here’s how you can do it:
Solution 2: Run an SFC Scan
There’s a chance Windows display the “Application failed because no QT platform plugin could be initialized” error due to corrupt system files. Fortunately, Windows has a built-in tool to help you fix the problem.
In the Start menu search bar, search for command prompt and select Run as administrator. Then, run the sfc /scannow command line. Windows will scan and automatically replace any corrupted system file.
Nothing worked for me, I'm getting the same error all the time. How can I resolve the error displayed in the figure above?
Any help will be appreciated, Thanks.
To add PyQt5's library path to your PATH environment variable:
1. Open the Edit Environment Variables
dialog.
2. Select the appropriate Path
variable (either User or System variables).
(Note: I have changed in system variables
)
3. Edit the variable and add the PyQt5
library path as three entries at the top.
4. Add the following 3 entries, and make sure the entries are in the desired order and at the top of path variable.
5. Save the changes.
C:\ProgramData\Anaconda3\envs\ann_tool\Lib\site-packages\PyQt5\Qt5\bin
C:\ProgramData\Anaconda3\envs\ann_tool\Lib\site-packages\PyQt5\Qt5\plugins
C:\ProgramData\Anaconda3\envs\ann_tool\Lib\site-packages\PyQt5\Qt5\plugins\platforms
6. Also, if you have a variable named: QT_PLUGIN_PATH
, you want to put this line at the top of the list:
C:\ProgramData\Anaconda3\envs\ann_tool\Lib\site-packages\PyQt5\Qt5\plugins
(Note: In my case, Anaconda is installed for all users so, Anaconda will be found in C:\ProgramData
)
7. Once you have saved the changes to your environment variables, it is necessary to Restart PyCharm in order for it to recognize and locate the updated libraries..