85

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

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Daivik Paul
  • 851
  • 1
  • 7
  • 4
  • Have a look at: http://stackoverflow.com/questions/20495620/qt-5-1-1-application-failed-to-start-because-platform-plugin-windows-is-missi. Otherwise try the advise in the message: "Reinstalling the application may fix this problem." – agold Feb 04 '17 at 16:40
  • 2
    Don't use screenshots to show us errors or code. "[Discourage screenshots of code and/or errors](https://meta.stackoverflow.com/questions/303812)" – the Tin Man Jun 11 '20 at 16:56
  • 2
    @Pawel solution is right or you may try `import matplotlib matplotlib.use('TKAgg') ` – dechiffre Nov 05 '21 at 08:50
  • the issue is with anaconda and matplotlib, use normal python, it's a know issue check here https://forum.qt.io/topic/133862/pyside6-does-not-work-with-anaconda – ironmann350 Mar 30 '22 at 14:14

28 Answers28

66

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.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
cxxl
  • 4,939
  • 3
  • 31
  • 52
  • 2
    great fix! But this fix created the same error for another software I had also needing Qt; so I have to recreate-it each time. Don't know if there is a way to avoid this. – agenis Oct 01 '17 at 17:03
  • 5
    It works for Python, but it is recommended not to add it to Environment Variables, because it breaks other systems. Now everytime I open my computer, Dropbox complains about missing Qt. Would be nice to know proper answer for this! – Antti A Jun 25 '20 at 11:35
  • 1
    @AnttiA 2 years later I am having the exact issue if I modify the environment variables - the problem itself is fixed, yet Dropbox no longer works properly. Were you able to find a solution to this problem? – Vesnog Jan 31 '22 at 00:56
33

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.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
rakidedigama
  • 714
  • 7
  • 11
  • 2
    This side-steps the problem, but this is a useful solution for some that should not be overlooked given the flexibility of matplotlib! – Dave C Nov 21 '18 at 22:25
  • Great. None of the solutions here worked except this one! – Joon. P Sep 13 '20 at 05:18
28

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

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\
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Osama Adly
  • 519
  • 5
  • 4
  • 1
    Could you elaborate how you solved this? Where does this problem come from? Your solution helped perfectly and I'd like to understand why. ^^ – Kai Winkler Sep 20 '21 at 13:07
23

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
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
silly
  • 887
  • 9
  • 9
  • 1
    This fixed my Conda environment. Removing qt also removed all the libraries that depend on it, so I had to reinstall them after. – Sarah N Jun 19 '20 at 07:03
  • 1
    This worked when I encountered `This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.` while trying to launch `labelImg`. Thx! – arun Feb 28 '21 at 16:42
  • 4
    this worked for me, but if you want to avoid reinstall all dependent packages, don't uninstall anything, just force reinstall: `conda install --force-reinstall pyqt` `conda install --force-reinstall qt` – Paris Char Mar 23 '21 at 17:14
21

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

Richard Ayling
  • 311
  • 2
  • 3
18

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
launchpadmcquack
  • 1,021
  • 1
  • 12
  • 19
  • 1
    I had used `conda-pack` to pack the environment and transfer it to another PC running the same OS. I did not notice that the **qt.conf** folder pointed to the absolute paths on the PC the environment was previously installed. Replacing these with the absolute paths on the new PC resolved the issue. – Vesnog Jan 31 '22 at 01:09
  • I also fixed the issue by editing 'envs\\qt.conf' files. Just set correct qt path in qt.conf file, the pycharm will work well. – Bob Yang Sep 15 '22 at 03:50
16

Just add a system variable:

QT_QPA_PLATFORM_PLUGIN_PATH

and set its value to

C:\Python34\Lib\site-packages\PyQt4\plugins\platforms

Voilà. Done

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
kunjung sherpa
  • 181
  • 1
  • 4
  • 1
    This also worked on a Centos box, inside an anaconda environment. Basically I had to set this before running the glue program `export QT_QPA_PLATFORM_PLUGIN_PATH=/opt/anaconda/plugins/platform` – Phil Aug 27 '20 at 14:44
  • My `PyQt5` folder has no `plugins` folder. – huang Jun 29 '22 at 09:18
12

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:\Users\xxxx\.spyder-py3\My_QtProjects\Project 1\dist\MyQt_1\PySide2\
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Sourabh Desai
  • 683
  • 7
  • 12
  • Two different environment variables and a number of solutions suggested here... Apparently this varies between versions of Qt5? For me this solution worked (Qt5.5.1) – user508402 Mar 15 '21 at 19:40
  • I was playing with PySide2 at the time, answers that I looked before was pointing towards PyQt5.x.x, fortunately, it worked in my case of PySide2 – Sourabh Desai Mar 16 '21 at 14:38
7

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>\Appdata\Local\Continuum\Anaconda2\Library\plugins.

  3. Restart Pycharm.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Pranzell
  • 2,275
  • 16
  • 21
  • 1
    You can use: setx QT_PLUGIN_PATH c:\users\%username%\anaconda3\Library\plugins from the command line for this. Useful for creating a batch file for fixing the issue on an install. – asylumax May 21 '20 at 13:32
4

I solved it by:

  • Adding a path:

    \Anaconda3\Lib\site-packages\PyQt5\Qt\bin to PATH.
    
  • Setting an environment variable:

    QT_PLUGIN_PATH as \Anaconda3\Lib\site-packages\PyQt5\Qt\plugins or \Anaconda3\Library\plugins.

  • Also, you can try:

    pyqt = os.path.dirname(PyQt5.__file__)
    os.environ['QT_PLUGIN_PATH'] = os.path.join(pyqt, "Qt/plugins")
    
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Zhongbo Chen
  • 493
  • 4
  • 12
  • 1
    I like the programmatically adding the `QT_PLUGIN_PATH` approach. In my case, it is `Qt5/plugins` from PyQt5 module. Setting the environment variable seems to interfere with other installed programs that also use Qt. – For Comment Nov 25 '21 at 18:13
3

First, use the command:

conda remove pyqt qt qtpy

Then install using:

conda install pyqt qt qtpy

This worked for me.

jdaz
  • 5,964
  • 2
  • 22
  • 34
  • 3
    Thanks a lot. For me though simply installing PyQt5 using ```pip install PyQt5``` solved the issue. – Hossein Jul 26 '20 at 13:33
2

Copy the folder

\Anaconda3\Library\plugins\platforms

to

\$\

where $ is your project interpreter folder. For example:

"\project\anaconda_env\Scripts\"

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

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
sontran
  • 29
  • 1
1

You may need to copy the "plugins" file in Anaconda3\Library. For example, on my computer it is

S:\Anaconda3\Library\plugins

to the same path of your .exe file.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
C.Conley
  • 21
  • 1
1

On Windows:

  1. Copy the folder platforms:

    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
    
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Daniel G
  • 11
  • 1
1

SOLUTION FOR WINDOWS USERS

Create new environment variable with:

name: QT_PLUGIN_PATH path: C:\yourpythonpath\Lib\site-packages\PyQt5\Qt\plugins

after that exe file will work

Pawel
  • 27
  • 1
1

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

(base) C:\ProgramData\Miniconda3\Lib\site-packages\PySide2\plugins\platforms>copy *.dll  C:\ProgramData\Miniconda3\Library\plugins\platforms\
yptheangel
  • 102
  • 5
  • Had the same problem with Pyside6 (pip installed) on a Windows computer using the miniforge package manager. Your solution worked here as well. Thanks – chiefenne Sep 03 '21 at 12:54
1

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.

Nils
  • 11
  • 1
0

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.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
0

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 :)

0

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")
0

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

Dharman
  • 30,962
  • 25
  • 85
  • 135
IvanPy
  • 51
  • 6
0

I installed a package that had a QT-gui that I didn't need.

So I just removed all the Qt modules from my environment.

pip freeze | grep -i qt

PyQt5==5.15.4
PyQt5-Qt5==5.15.2
PyQt5-sip==12.9.0
QtPy==1.9.0

pip uninstall PyQt5
pip uninstall PyQt5-Qt5
pip uninstall PyQt5-sip
pip uninstall QtPy

Problem solved.

Duane
  • 4,572
  • 6
  • 32
  • 33
0

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:

\site-packages\PyQt6\Qt6\plugins\platforms
\site-packages\PySide6\plugins\platforms

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.

  • Please don't post duplicate answers. If you want to edit [Osama Adly's answer](https://stackoverflow.com/a/52281936/16775594) to improve on it, you can do so by clicking the [edit](https://stackoverflow.com/posts/52281936/edit) link underneath the answer. See [answer] for more information. – Sylvester Kruin Mar 30 '22 at 21:42
0

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.

it has be a know issue here enter link description here

ironmann350
  • 371
  • 2
  • 4
0

In my situation, I did everything listed above and on other forum post:

  1. Copying and pasting files
  2. Adding system variables
  3. Uninstalling, downloading, and reinstalling programs
  4. Restarting the computer
  5. Enabling debugging mode
  6. Running the source code instead of the compiled program
  7. Running sfc /scannow

All of this did not work. In my case, the solution was to update Windows. The computer was apparently running a very outdated version of Windows (10?) After 2-3 hours of installing the update, problem solved. Source/Inspiration: https://www.partitionwizard.com/clone-disk/no-qt-platform-plugin-could-be-initialized.html

Amit Shah
  • 3
  • 4
-1

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

Orsiris de Jong
  • 2,819
  • 1
  • 26
  • 48
-1

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:\temp\BlueTouth )
  2. 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 */

  3. Result should be something like that:

C:\temp\BlueTouth\btscanner.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:\temp\BlueTouth\translations...
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:\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.

Nikolai Shevchenko
  • 7,083
  • 8
  • 33
  • 42
SPirev
  • 21
  • 2
-2

copy platforms from Anaconda3\Library\plugins and put it in the Anaconda3. for env put the platforms in the specific env\ folder

aawan
  • 1