# Buggy code
def __init__(self, parent):
    SpyderPluginWidget.__init__(self, parent)

    self.tabwidget = None
    self.menu_actions = None

    self.extconsole = None  # External console plugin
    self.help = None  # Help plugin
    self.historylog = None  # History log plugin
    self.variableexplorer = None  # Variable explorer plugin
    self.editor = None  # Editor plugin

    self.master_clients = 0
    self.clients = []
    self.mainwindow_close = False
    self.create_new_client_if_empty = True

    # Initialize plugin
    self.initialize_plugin()

    layout = QVBoxLayout()
    self.tabwidget = Tabs(self, self.menu_actions)
    if hasattr(self.tabwidget, "setDocumentMode") and not sys.platform == "darwin":
        # Don't set document mode to true on OSX because it generates
        # a crash when the console is detached from the main window
        # Fixes Issue 561
        self.tabwidget.setDocumentMode(True)
    self.tabwidget.currentChanged.connect(self.refresh_plugin)
    self.tabwidget.move_data.connect(self.move_tab)

    self.tabwidget.set_close_function(self.close_client)

    if sys.platform == "darwin":
        tab_container = QWidget()
        tab_container.setObjectName("tab-container")
        tab_layout = QHBoxLayout(tab_container)
        tab_layout.setContentsMargins(0, 0, 0, 0)
        tab_layout.addWidget(self.tabwidget)
        layout.addWidget(tab_container)
    else:
        layout.addWidget(self.tabwidget)

    # Find/replace widget
    self.find_widget = FindReplace(self)
    self.find_widget.hide()
    self.register_widget_shortcuts(self.find_widget)
    layout.addWidget(self.find_widget)

    self.setLayout(layout)

    # Accepting drops
    self.setAcceptDrops(True)


# Traceback (IndexError)
import tensorflow
Traceback (most recent call last):

File "<ipython-input-1-a649b509054f>", line 1, in <module>
import tensorflow

File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *

File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 100, in <module>
from tensorflow.python.platform import app

File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 23, in <module>
from tensorflow.python.platform import flags

File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/flags.py", line 25, in <module>
_global_parser = _argparse.ArgumentParser()

File "/usr/lib/python2.7/argparse.py", line 1586, in __init__
prog = _os.path.basename(_sys.argv[0])

IndexError: list index out of range

# Fixed code
def __init__(self, parent, testing=False):
    """Ipython Console constructor."""
    SpyderPluginWidget.__init__(self, parent)

    self.tabwidget = None
    self.menu_actions = None

    self.extconsole = None  # External console plugin
    self.help = None  # Help plugin
    self.historylog = None  # History log plugin
    self.variableexplorer = None  # Variable explorer plugin
    self.editor = None  # Editor plugin

    self.master_clients = 0
    self.clients = []
    self.mainwindow_close = False
    self.create_new_client_if_empty = True
    self.testing = testing

    # Initialize plugin
    if not self.testing:
        self.initialize_plugin()

    layout = QVBoxLayout()
    self.tabwidget = Tabs(self, self.menu_actions)
    if hasattr(self.tabwidget, "setDocumentMode") and not sys.platform == "darwin":
        # Don't set document mode to true on OSX because it generates
        # a crash when the console is detached from the main window
        # Fixes Issue 561
        self.tabwidget.setDocumentMode(True)
    self.tabwidget.currentChanged.connect(self.refresh_plugin)
    self.tabwidget.move_data.connect(self.move_tab)

    self.tabwidget.set_close_function(self.close_client)

    if sys.platform == "darwin":
        tab_container = QWidget()
        tab_container.setObjectName("tab-container")
        tab_layout = QHBoxLayout(tab_container)
        tab_layout.setContentsMargins(0, 0, 0, 0)
        tab_layout.addWidget(self.tabwidget)
        layout.addWidget(tab_container)
    else:
        layout.addWidget(self.tabwidget)

    # Find/replace widget
    self.find_widget = FindReplace(self)
    self.find_widget.hide()
    if not self.testing:
        self.register_widget_shortcuts(self.find_widget)
    layout.addWidget(self.find_widget)

    self.setLayout(layout)

    # Accepting drops
    self.setAcceptDrops(True)