diff --git a/qcodes/__init__.py b/qcodes/__init__.py index f7a65d3adeab..070db3c3b880 100644 --- a/qcodes/__init__.py +++ b/qcodes/__init__.py @@ -2,13 +2,16 @@ # flake8: noqa (we don't need the "<...> imported but unused" error) +import os # just for convenience in debugging, so we don't have to # separately import multiprocessing from multiprocessing import active_children from qcodes.version import __version__ from qcodes.process.helpers import set_mp_method -from qcodes.utils.helpers import in_notebook +from qcodes.utils.helpers import in_notebook, frontend + + # code that should only be imported into the main (notebook) thread # in particular, importing matplotlib in the side processes takes a long @@ -28,7 +31,9 @@ 'try "from qcodes.plots.pyqtgraph import QtPlot" ' 'to see the full error') - from qcodes.widgets.widgets import show_subprocess_widget + # only load the show_subprocess_widget when running jupyter notebook + if frontend()=='notebook': + from qcodes.widgets.widgets import show_subprocess_widget from qcodes.station import Station from qcodes.loops import get_bg, halt_bg, Loop diff --git a/qcodes/plots/base.py b/qcodes/plots/base.py index 2c7dcc824dcd..ddda78573354 100644 --- a/qcodes/plots/base.py +++ b/qcodes/plots/base.py @@ -3,8 +3,12 @@ ''' from IPython.display import display -from qcodes.widgets.widgets import HiddenUpdateWidget +from qcodes.utils.helpers import frontend +if frontend()=='notebook': + from qcodes.widgets.widgets import HiddenUpdateWidget +else: + HiddenUpdateWidget=None class BasePlot: @@ -26,7 +30,7 @@ def __init__(self, interval=1, data_keys='xyz'): self.data_updaters = set() self.interval = interval - if interval: + if interval and HiddenUpdateWidget: self.update_widget = HiddenUpdateWidget(self.update, interval) display(self.update_widget) diff --git a/qcodes/plots/qcmatplotlib.py b/qcodes/plots/qcmatplotlib.py index be55d65b7e5d..2824df0f31de 100644 --- a/qcodes/plots/qcmatplotlib.py +++ b/qcodes/plots/qcmatplotlib.py @@ -10,7 +10,6 @@ from .base import BasePlot - class MatPlot(BasePlot): ''' Plot x/y lines or x/y/z heatmap data. The first trace may be included diff --git a/qcodes/utils/helpers.py b/qcodes/utils/helpers.py index ba269dd7599c..4d0e33488fb5 100644 --- a/qcodes/utils/helpers.py +++ b/qcodes/utils/helpers.py @@ -4,6 +4,7 @@ import logging import math import sys +import os import io import numpy as np import json @@ -35,6 +36,13 @@ def tprint(string, dt=1, tag='default'): print(string) _tprint_times[tag] = time.time() +def frontend(): + """ Return frontend used + + Returns + frontend (string): frontend used. Default is notebook + """ + return os.environ.get('QCODESFRONTEND', 'notebook') def in_notebook(): """