I had the same problem with Anaconda3 4.2.0 and 4.3.0.1 (64-bit). When I tried to run a simple program that uses matplotlib, I got this error message:
This application failed to start because it could not find or load the Qt platform plugin "windows"
Reinstalling the application may fix this problem.
Reinstalling didn't fix it.
What helped was this (found here):
Look for the Anaconda directory and set the Library\plugins subdir (here c:\ProgramData\Anaconda3\Library\plugins) as environment variable QT_PLUGIN_PATH under Control Panel / System / Advanced System Settings / Environment Variables.
After setting the variable you might need to restart PyCharm, if the change does not have an immediate effect.
Even though after that the command line Python worked, TexWorks (which uses Qt as well) displayed an error message very much like it. Setting the QT_PLUGIN_PATH to the directory containing TexWorks' Qt DLLs (here C:\Users\chris\AppData\Local\Programs\MiKTeX 2.9\miktex\bin\x64) fixed the problem for both programs.
I had a similar problem with PyCharm where things worked great in main run but not in debugger, getting the same error message. This happened for me because I had moved my Anaconda installation to a different directory. The debugger goes and checks a qt.conf file that is located at the same place as python. This location can be found by running import sys; print sys.executable. I found this solution through a pile of web searches and it was buried deep here. The qt.conf file needs to have correct paths for debugger to work.
If the Pycharm console or debugger are showing "Could not find or load the Qt platform plugin windows", the Python EXE file may be located at a different location for the PyCharm interpreter. You might manually select it in File -> Settings -> Interpreter.
Set the working directory: File -> Settings -> Build, Execution, Deployment -> Console -> Python Console -> Working directory. Set it to the parent directory where your all code exists.
Open Control Panel -> System Settings -> Advanced System Settings -> Environment Variables -> New. Set the variable name QT_PLUGIN_PATH , Variable Directory: Users\<Username>\Appdata\Local\Continuum\Anaconda2\Library\plugins.
I found that this was being caused by having the MiKTeX binaries in my PATH variable; and the wrong Qt dll's were being found. I just needed to re-arrange the PATH entries.
I have found a solution that worked for me. This solution includes a code snippet to add before you import any modules from Pyside2 or PyQt5 package. See "Qt platform plugin "windows" #2" for more information.
This code snippet is from the link:
import 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
from PySide2.QtWidgets import *
'''
Your code goes here
'''
This solution works for PyQt5 and PySide2 modules.
I don't know if it's relevant but I added the QT_PLUGIN_PATH environment variable in the system before.
That solution enabled me to test PySide2 scripts in IDLE.
However, I faced the same error when I tried to run a bundled script (exe).
With some shallow debugging, it's evident that plugin folder itself is missing. I fixed the problem by adding the plugin folder in the appropriate location:
I had the same issue with Qt 5.9 example btscanner.exe. What works in my case is:
Create a folder where is btscanner.exe ( my is c:\temp\BlueTouth )
Run from command prompt windeployqt.exe as follow:
c:\qt\qt5.9.0\msvc2015\bin\windeployqt c:\temp\BlueTouth
/* windeplyqt is the standard Qt tool to packet your application with any needed
libraries or extra files and ready to deploy on other machine */
If you take e look at c:\temp\BlueTouth folder will see
the folders iconengines, imageformats, platforms, translations,
and files D3Dcompiler_47.dll, libEGL.dll, libGLESV2.dll, opengl32sw.dll,
Qt5Bluetouth.dll, Qt5Core.dll, Qt5Gui.dll, Qt5Svg.dll, Qt5Widgets.dll.
These are all of the files and folders need to run btscanner.exe on
this or another machine. Just copy whole folder on other machine and
run the file.
I have the same issue and fixed in this way
In Anaconda installation folder I went to : (change it to your installed path):
C:\ProgramData\Anaconda3\Lib\site-packages\PySide2
Edit this file by adding the following code lines :
# below the line 23 type.__signature__
pyside_package_dir = os.path.abspath(os.path.dirname(__file__))
dirname = os.path.dirname(__file__)
plugin_path = os.path.join(dirname, 'plugins', 'platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path
save this file and try again and the issue should be gone :)
I know everyone above had provided various ways to fix OP's issue. I just want to add on some suggestions.
By adding the QT_PLUGIN_PATH = C:\Users{YOUR_USERNAME}\Anaconda3\Library\plugins as your local machine environment variable it helps to fix OP's PyCharm issue above. However, this will break other systems in your machine like: Dropbox reports missing QT, AMD settings fails to launch(which happens on my side) etc.
Instead of adding QT_PLUGIN_PATH to your machine locally, one can add the environment variable in PyCharm's python interpreter setting as shown below:
This method not only allow your PyCharm's python.exe able to search those DLLs but also not breaking other systems' QT lookup PATH.
I had the same problem with Anaconda. For me, although not very elegant, the fastest solution was to unistall and reinstall Ananconda completely. After that, everything worked well again.
Inspired by Osama Adly, I think this kind of problems are all caused by Anaconda configuration for Qt DLLs on Windows platform.
Just try to install PyQt/PySide in an empty environment besides Anaconda, for example a standalone Python program. You will find that the plugins about platforms are in the site-package directory itself.
For comparation:
But it seems that Anaconda contains some software depending on PyQt5 or Qt. Anaconda moves the platforms directory from PyQt5 to another folder and this folder might be contained in the PATH variable when using Anaconda.
\Anaconda3\Library\plugins\platforms
This could lead to unneccessary problems. These DLLs reserve the same name across different generation of Qt. For example, when I tried PySide6 in a virtual environment created with Anaconda, its call for DLLs will mistakenly use the Qt5 DLLS rather than the DLLs in its folder.
if you are using anaconda/miniconda with matplotlib installed.
you'll have to install uninstall anaconda/miniconda and use miniconda without matplotlib, a fix is to use normal python not anaconda.