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

前端 未结 21 880
迷失自我
迷失自我 2020-12-02 13:00

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?

相关标签:
21条回答
  • 2020-12-02 13:47

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

    0 讨论(0)
  • 2020-12-02 13:49

    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

    0 讨论(0)
  • 2020-12-02 13:53

    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.

    0 讨论(0)
  • 2020-12-02 13:56

    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.

    0 讨论(0)
  • 2020-12-02 13:56

    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\
    
    0 讨论(0)
  • 2020-12-02 13:56

    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
      
    0 讨论(0)
提交回复
热议问题