Question

[Solved] How to fix “could not find or load the Qt platform plugin windows” while using Matplotlib in PyCharm

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?

enter image description here

Solution #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 Libraryplugins subdir (here c:ProgramDataAnaconda3Libraryplugins) 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:UserschrisAppDataLocalProgramsMiKTeX 2.9miktexbinx64) fixed the problem for both programs.

Respondent: cxxl

Solution #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.)

Respondent: Richard Ayling

Solution #3:

If you are running PyQt5 and PySide2, this solved the problem for me:

Copy the following files:

Anaconda3Libsite-packagesPySide2pluginsplatformsqminimal.dll
Anaconda3Libsite-packagesPySide2pluginsplatformsqoffscreen.dll
Anaconda3Libsite-packagesPySide2pluginsplatformsqwindows.dll

to:

Anaconda3Librarypluginsplatforms
Respondent: Osama Adly

Solution #4:

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
Respondent: launchpadmcquack

Solution #5:

I tried the following at Anaconda’s prompt, and it solved this problem:

conda remove qt
conda remove pyqt 
conda install qt 
conda install pyqt
Respondent: Shu Zhang

Solution #6:

Just add a system variable:

QT_QPA_PLATFORM_PLUGIN_PATH

and set its value to

C:Python34Libsite-packagesPyQt4pluginsplatforms

Voilà. Done

Respondent: kunjung sherpa

Solution #7:

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.

Respondent: rakidedigama

Solution #8:

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.

  1. 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.

  2. Open Control Panel -> System Settings -> Advanced System Settings -> Environment Variables -> New. Set the variable name QT_PLUGIN_PATH , Variable Directory: Users<Username>AppdataLocalContinuumAnaconda2Libraryplugins.

  3. Restart Pycharm.

Respondent: Pranzell

Solution #9:

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:

C:Usersxxxx.spyder-py3My_QtProjectsProject 1distMyQt_1PySide2
Respondent: Sourabh Desai

Solution #10:

First, use the command:

conda remove pyqt qt qtpy

Then install using:

conda install pyqt qt qtpy

This worked for me.

Respondent: ??????

Solution #11:

I solved it by:

  • Adding a path:

    Anaconda3Libsite-packagesPyQt5Qtbin to PATH.
    
  • Setting an environment variable:

    QT_PLUGIN_PATH as Anaconda3Libsite-packagesPyQt5Qtplugins or Anaconda3Libraryplugins.

  • Also, you can try:

    pyqt = os.path.dirname(PyQt5.__file__)
    os.environ['QT_PLUGIN_PATH'] = os.path.join(pyqt, "Qt/plugins")
    
Respondent: Zhongbo Chen

Solution #12:

Copy the folder

Anaconda3Librarypluginsplatforms

to

$

where $ is your project interpreter folder. For example:

"projectanaconda_envScripts"

because PyCharm calls the python.exe in this folder, not the one in Anaconda3.

Respondent: sontran

Solution #13:

On Windows:

  1. Copy the folder platforms:

    C:Users%USERNAME%AppDataRoamingpyinstallerbincache00_py35_64bitpyqt5qtpluginsplatforms 
    
  2. Paste the folder platform into the folder location of the file .exe:

    Example:

    c:MyFolderyourFile.exe
    c:MyFolderplatforms
    
Respondent: Daniel G

Solution #14:

You may need to copy the “plugins” file in Anaconda3Library. For example, on my computer it is

S:Anaconda3Libraryplugins

to the same path of your .exe file.

Respondent: C.Conley

Solution #15:

Please try this in the script

qt_path= os.path.dirname(PyQt5.__file__)
os.environ['QT_PLUGIN_PATH'] = os.path.join(qt_path, "Qt/plugins")
Respondent: Ammar Nourallah

Solution #16:

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}Anaconda3Libraryplugins 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:
enter image description here

This method not only allow your PyCharm’s python.exe able to search those DLLs but also not breaking other systems’ QT lookup PATH.

Thanks

Respondent: IvanPy

Solution #17:

I have the same issue and fixed in this way
In Anaconda installation folder I went to : (change it to your installed path):
C:ProgramDataAnaconda3Libsite-packagesPySide2
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 🙂

Respondent: Abdelrahman Farag

Solution #18:

I had the same issue. Following “Activating an environment” in “Managing environments” solved the issue.

In the command line:

conda activate myenv

where myenv=base for my setup.

Respondent: Pier-Yves Lessard

Solution #19:

copy the plugins from PySide2 and paste and overwrite the existing plugins in Miniconda worked for me.

(base) C:ProgramDataMiniconda3Libsite-packagesPySide2pluginsplatforms>copy *.dll  C:ProgramDataMiniconda3Librarypluginsplatforms
Respondent: yptheangel

Solution #20:

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

Respondent: Orsiris de Jong

Solution #21:

SOLUTION FOR WINDOWS USERS

Create new environment variable with:

name: QT_PLUGIN_PATH
path: C:yourpythonpathLibsite-packagesPyQt5Qtplugins

after that exe file will work

Respondent: Pawel

Solution #22:

copy platforms from Anaconda3Libraryplugins and put it in the Anaconda3.
for env put the platforms in the specific env folder

Respondent: aawan

Solution #23:

I had the same issue with Qt 5.9 example btscanner.exe. What works in my case is:

  1. Create a folder where is btscanner.exe ( my is c:tempBlueTouth )
  2. Run from command prompt windeployqt.exe as follow:
    c:qtqt5.9.0msvc2015binwindeployqt c:tempBlueTouth
    /* windeplyqt is the standard Qt tool to packet your application with any needed
    libraries or extra files and ready to deploy on other machine */

  3. Result should be something like that:

C:tempBlueTouthbtscanner.exe 32 bit, release executable
Adding Qt5Svg for qsvgicon.dll
Skipping plugin qtvirtualkeyboardplugin.dll due to disabled dependencies.
Direct dependencies: Qt5Bluetooth Qt5Core Qt5Gui Qt5Widgets
All dependencies   : Qt5Bluetooth Qt5Core Qt5Gui Qt5Widgets
To be deployed     : Qt5Bluetooth Qt5Core Qt5Gui Qt5Svg Qt5Widgets
Warning: Cannot find Visual Studio installation directory, VCINSTALLDIR is not set.
Updating Qt5Bluetooth.dll.
Updating Qt5Core.dll.
Updating Qt5Gui.dll.
Updating Qt5Svg.dll.
Updating Qt5Widgets.dll.
Updating libGLESV2.dll.
Updating libEGL.dll.
Updating D3Dcompiler_47.dll.
Updating opengl32sw.dll.
Patching Qt5Core.dll...
Creating directory C:/temp/BlueTouth/iconengines.
Updating qsvgicon.dll.
Creating directory C:/temp/BlueTouth/imageformats.
Updating qgif.dll.
Updating qicns.dll.
Updating qico.dll.
Updating qjpeg.dll.
Updating qsvg.dll.
Updating qtga.dll.
Updating qtiff.dll.
Updating qwbmp.dll.
Updating qwebp.dll.
Creating directory C:/temp/BlueTouth/platforms.
Updating qwindows.dll.
Creating C:tempBlueTouthtranslations...
Creating qt_bg.qm...
Creating qt_ca.qm...
Creating qt_cs.qm...
Creating qt_da.qm...
Creating qt_de.qm...
Creating qt_en.qm...
Creating qt_es.qm...
Creating qt_fi.qm...
Creating qt_fr.qm...
Creating qt_gd.qm...
Creating qt_he.qm...
Creating qt_hu.qm...
Creating qt_it.qm...
Creating qt_ja.qm...
Creating qt_ko.qm...
Creating qt_lv.qm...
Creating qt_pl.qm...
Creating qt_ru.qm...
Creating qt_sk.qm...
Creating qt_uk.qm...
  1. If you take e look at c:tempBlueTouth 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.

Respondent: SPirev

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy