# Buggy code
def configure_shellwidget(self, give_focus=True):
    """Configure shellwidget after kernel is started"""
    if give_focus:
        self.get_control().setFocus()

    # Set exit callback
    self.shellwidget.set_exit_callback()

    # To save history
    self.shellwidget.executing.connect(self.add_to_history)

    # For Mayavi to run correctly
    self.shellwidget.executing.connect(self.shellwidget.set_backend_for_mayavi)

    # To update history after execution
    self.shellwidget.executed.connect(self.update_history)

    # To update the Variable Explorer after execution
    self.shellwidget.executed.connect(self.shellwidget.refresh_namespacebrowser)

    # To enable the stop button when executing a process
    self.shellwidget.executing.connect(self.enable_stop_button)

    # To disable the stop button after execution stopped
    self.shellwidget.executed.connect(self.disable_stop_button)

    # To show kernel restarted/died messages
    self.shellwidget.sig_kernel_restarted.connect(self.kernel_restarted_message)

    # To correctly change Matplotlib backend interactively
    self.shellwidget.executing.connect(self.shellwidget.change_mpl_backend)

    # To show env and sys.path contents
    self.shellwidget.sig_show_syspath.connect(self.show_syspath)
    self.shellwidget.sig_show_env.connect(self.show_env)

    # To sync with working directory toolbar
    self.shellwidget.executed.connect(self.shellwidget.get_cwd)

    # To apply style
    if not create_qss_style(self.shellwidget.syntax_style)[1]:
        self.shellwidget.silent_execute("%colors linux")
    else:
        self.shellwidget.silent_execute("%colors lightbg")

    # To hide the loading page
    self.shellwidget.sig_prompt_ready.connect(self._hide_loading_page)


# Traceback (ModuleNotFoundError)
Traceback (most recent call last):

File "<ipython-input-1-9701cca0214f>", line 1, in <module>
runfile('/home/mukundan/nextcloud/documents/programming/python/misc/plot_test.py', wdir='/home/mukundan/nextcloud/documents/programming/python/misc')

File "/usr/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 710, in runfile
execfile(filename, namespace)

File "/usr/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 101, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)

File "/home/mukundan/nextcloud/documents/programming/python/misc/plot_test.py", line 9, in <module>
import matplotlib.pyplot as plt

File "/usr/lib64/python3.6/site-packages/matplotlib/pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()

File "/usr/lib64/python3.6/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)

ModuleNotFoundError: No module named 'matplotlib.backends.backend_qt5agg'

# Fixed code
def configure_shellwidget(self, give_focus=True):
    """Configure shellwidget after kernel is started"""
    if give_focus:
        self.get_control().setFocus()

    # Set exit callback
    self.shellwidget.set_exit_callback()

    # To save history
    self.shellwidget.executing.connect(self.add_to_history)

    # For Mayavi to run correctly
    self.shellwidget.executing.connect(self.shellwidget.set_backend_for_mayavi)

    # To update history after execution
    self.shellwidget.executed.connect(self.update_history)

    # To update the Variable Explorer after execution
    self.shellwidget.executed.connect(self.shellwidget.refresh_namespacebrowser)

    # To enable the stop button when executing a process
    self.shellwidget.executing.connect(self.enable_stop_button)

    # To disable the stop button after execution stopped
    self.shellwidget.executed.connect(self.disable_stop_button)

    # To show kernel restarted/died messages
    self.shellwidget.sig_kernel_restarted.connect(self.kernel_restarted_message)

    # To correctly change Matplotlib backend interactively
    self.shellwidget.executing.connect(self.shellwidget.change_mpl_backend)

    # To show env and sys.path contents
    self.shellwidget.sig_show_syspath.connect(self.show_syspath)
    self.shellwidget.sig_show_env.connect(self.show_env)

    # To sync with working directory toolbar
    self.shellwidget.executed.connect(self.shellwidget.get_cwd)

    # To apply style
    if not create_qss_style(self.shellwidget.syntax_style)[1]:
        self.shellwidget.silent_execute("%colors linux")
    else:
        self.shellwidget.silent_execute("%colors lightbg")

    # To hide the loading page
    self.shellwidget.sig_prompt_ready.connect(self._hide_loading_page)

    # Show possible errors when setting Matplotlib backend
    self.shellwidget.sig_prompt_ready.connect(self._show_mpl_backend_errors)