How to avoid PyCharm console crash "WARNING: QApplication was not created in the main() thread" when plotting with matplotlib?
I sent this question to JetBrains: https://youtrack.jetbrains.com/issue/PY-36136
They couldn't find a solution yet, but the workaround they suggested is the following:
Disable Show plots in tool window in File | Settings | Tools | Python Scientific.
This worked for me, although it doesn't plot in the PyCharm window.
There several things you can try:
First, you can try to update the Qt. You may have some older version. Run
print(plt.get_backend())
to verify which backend you are using. If you are using Qt4
, try Qt5
back end.
Next, update Qt5
to the latest version via
pip install --upgrade PyQt5
Also, you can try ditching Qt
and switch to Tk
back end: add
import matplotlib
matplotlib.use('TkAgg')
before importing pyplot