Error “could not find or load the Qt platform plug

2019-02-08 07:40发布

问题:

I am getting the error "could not find or load the Qt platform plugin windows" while using matplotlib in PyCharm.

How can I solve this?

回答1:

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.

Et voilà!

Update: 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.



回答2:

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.

(Dependency Walker is such a useful tool.)



回答3:

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.

My qt.conf files looks like this in notepad:

[Paths]
Prefix = E:/python/Anaconda3_py35/Library
Binaries = E:/python/Anaconda3_py35/Library/bin
Libraries = E:/python/Anaconda3_py35/Library/lib
Headers = E:/python/Anaconda3_py35/Library/include/qt


回答4:

I tried the following in Anaconda prompt, and it solved this problem:

conda remove qt

conda remove pyqt

conda install qt

conda install pyqt



回答5:

Pycharm Console or Debugger showing this issue - Could not find or load the Qt platform plugin windows

Reason - Python exe file may be located at a different location for Pycharm interpreter, you might manually select it in file,settings,interpreter.

Solution -

  1. Set the working directory. File ->Settings-> Build, Execution, Deployment ->Console ->Python Console -> Working directory. Set it to parent directory where your all codes are present.

  2. Open Control Panel-> System Settings -> Advanced System Settings ->Environment Variables ->New. Set Variable Name: QT_PLUGIN_PATH , Variable Directory:Users\\Appdata\Local\Continuum\Anaconda2\Library\plugins

  3. Restart Pycharm.



回答6:

If you want to visualize your matplotlibs in an alternative way, use a different backend that generates the graphs, charts etc.

import matplotlib matplotlib.use('TKAgg')

This worked for me.



回答7:

If installed PyQt5 and PySide2, I solved problem

Copy the following files

\Anaconda3\Lib\site-packages\PySide2\plugins\platforms\qminimal.dll
\Anaconda3\Lib\site-packages\PySide2\plugins\platforms\qoffscreen.dll
\Anaconda3\Lib\site-packages\PySide2\plugins\platforms\qwindows.dll

to

\Anaconda3\Library\plugins\platforms\


回答8:

You may need to copy the "plugins" file in on "Anaconda3\Library"(for example in my computer is "S:\Anaconda3\Library\plugins") to the same path of your .exe file.



回答9:

On Windows

1- Copy the folder plastforms: C:\Users\%USERNAME%\AppData\Roaming\pyinstaller\bincache00_py35_64bit\pyqt5\qt\plugins\platforms

2- Paste the folder platform into the folder location of the file .exe

Example: c:\MyFolder\yourFile.exe c:\MyFolder\platforms



回答10:

I copy the folder \Anaconda3\Library\plugins\platforms to \$\ where $ represents your project interpreter folder (Ex:"\project\anaconda_env\Scripts\") , because PyCharm calls the python.exe in this folder, not the one in \Anaconda3. and solve my problem.



回答11:

In my case, I had multiple combined problems in order to make PyQt5 run on Windows, see DLL load failed when importing PyQt5