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?
copy platforms from Anaconda3\Library\plugins and put it in the Anaconda3. for env put the platforms in the specific env\ folder
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
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.
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
.
Restart Pycharm.
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\
On Windows:
Copy the folder platforms:
C:\Users\%USERNAME%\AppData\Roaming\pyinstaller\bincache00_py35_64bit\pyqt5\qt\plugins\platforms
Paste the folder platform into the folder location of the file .exe:
Example:
c:\MyFolder\yourFile.exe
c:\MyFolder\platforms