When the python wrapper is imported and used before matplotlib is imported, every plot call to matplotlib crashes the python process. My guess is that the python wrapper somehow prevents matplotlib loading the correct Qt backend. It is a minor issue as loading all modules first does not trigger the problem. Nonetheless, in interactive sessions users will expect that the order of imports does not matter.
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2017.1\helpers\pydev\pydevd.py", line 1578, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2017.1\helpers\pydev\pydevd.py", line 1015, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "D:/Projects/prostate-epithelium-segmentation/main.py", line 70, in <module>
import matplotlib.pyplot as plt
File "C:\Users\wouterbulten\Anaconda2\envs\cadcourse\lib\site-packages\matplotlib\pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "C:\Users\wouterbulten\Anaconda2\envs\cadcourse\lib\site-packages\matplotlib\backends\__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "C:\Users\wouterbulten\Anaconda2\envs\cadcourse\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 16, in <module>
from .backend_qt5 import QtCore
File "C:\Users\wouterbulten\Anaconda2\envs\cadcourse\lib\site-packages\matplotlib\backends\backend_qt5.py", line 26, in <module>
import matplotlib.backends.qt_editor.figureoptions as figureoptions
File "C:\Users\wouterbulten\Anaconda2\envs\cadcourse\lib\site-packages\matplotlib\backends\qt_editor\figureoptions.py", line 20, in <module>
import matplotlib.backends.qt_editor.formlayout as formlayout
File "C:\Users\wouterbulten\Anaconda2\envs\cadcourse\lib\site-packages\matplotlib\backends\qt_editor\formlayout.py", line 56, in <module>
from matplotlib.backends.qt_compat import QtGui, QtWidgets, QtCore
File "C:\Users\wouterbulten\Anaconda2\envs\cadcourse\lib\site-packages\matplotlib\backends\qt_compat.py", line 137, in <module>
from PyQt4 import QtCore, QtGui
ImportError: No module named PyQt4
As Qt5 is installed there is no need for matplotlib to load Qt4.
Setting the backend explictely in a interactive session (i.e. %matplotlib qt5
) also solves the problem.