PyQt5 gets “No module named 'PyQt4'” error calling matplotlib.pyplot in Python 3.5

后端 未结 6 1809
春和景丽
春和景丽 2021-02-11 08:19

I am using Anaconda with Python 3.5.2, Matplotlib 2.0.2, PyQt5.6 on a windows 10 machine. When I import matplotlib.pyplot as plt I get the following error:

...
         


        
6条回答
  •  遇见更好的自我
    2021-02-11 09:17

    I had faced the same problem and here is how I fixed it.

    Look into your matplotlib configuration file which is often located at path-to/site-packages/matplotlib/mpl-data/matplotlibrc or path-to/Anaconda3/envs/your_env_name/Lib/site-packages/matplotlib/mpl-data/matplotlibrc

    See an example of matplotlibrc here https://github.com/daler/matplotlibrc/blob/master/rc/default

    If you have pyqt5.x.x installed and have the statement 'backend : Qt5Agg' in matplotlibrc, then to use '%matplotlib qt', change '#backend.qt4 : PyQt4' to '#backend.qt4 : PyQt5'.

    For an Anaconda environment, reactivate the environment.

    Note if you update matplotlib in the future, your matplotlibrc will automatically be overwritten.

提交回复
热议问题