def launch_notebook(port): # launch the notebook import sys import re import socket from IPython.terminal.ipapp import launch_new_instance argv = sys.argv[:1] argv.append('notebook') argv.append('--config={profile_path}/jupyter_notebook_config.py'.format(profile_path=jupyter_config_path)) # check if we passed in a port that is different from the one in the # configuration with open("{profile_path}/jupyter_notebook_config.py".format(profile_path=jupyter_config_path), 'r') as conf: conf_port = int(re.findall('port = (\d+)', conf.read())[0]) if conf_port != port: print(bc.WARNING + "Overriding the port found in the existing configuration" + bc.ENDC) argv.append('--port={port}'.format(port=port)) # determine if we're running on a compute node if 'LSB_HOSTS' in os.environ: compute = True else: compute = False sys.argv = argv if compute: ip = socket.gethostbyname(socket.gethostname()) else: ip = 'localhost' print(bc.BOLD + "To access the notebook, inspect the output below for the port number, then point your browser to https://{ip}:<port_number>".format(ip=ip) + bc.ENDC) launch_new_instance()
def run(qt=False): argv = sys.argv # Install tango profile if not is_installed(): install(verbose=False) # Install jupyter kernel spec kernel_installed = install_kernel(verbose=False) # Run with jupyter if qt and kernel_installed: argv.append("--kernel=tango") app_class = patch_qt_console() return app_class.launch_instance() # Add tango profile if not any(arg.startswith('--profile=') for arg in argv): argv.append("--profile=tango") # Configure qt if qt: patch_qt_console() if 'qtconsole' not in argv: argv.insert(1, 'qtconsole') argv.append('--pylab=inline') # Run launch_new_instance()
def notebook(): from IPython.terminal.ipapp import launch_new_instance from socket import gethostname import warnings print('Installing in develop mode') run('python setup.py develop', hide='out') print('Changing to notebooks folder') here = os.path.dirname(__file__) os.chdir(os.path.join(here, 'notebooks')) old_argv = sys.argv[:] # Taken from here: # http://stackoverflow.com/questions/ # 26338688/start-ipython-notebook-with-python-file try: warnings.filterwarnings("ignore", module = "zmq.*") sys.argv = ['ipython', 'notebook'] sys.argv.append("--IPKernelApp.pylab='inline'") sys.argv.append("--NotebookApp.ip=" + gethostname()) sys.argv.append("--NotebookApp.open_browser=True") print('Invoking "' + ' '.join(sys.argv) + '"') launch_new_instance() finally: # Not sure this is strictly necessary... sys.argv = old_argv os.chdir(here) print('Removing development package...') run('python setup.py develop -u', hide='out')
def run(self): warnings.filterwarnings("ignore", module = "zmq.*") sys.argv.append("notebook") sys.argv.append("--IPKernelApp.pylab='inline'") sys.argv.append("--NotebookApp.ip=localhost") sys.argv.append("--NotebookApp.open_browser=False") sys.argv.append('--NotebookApp.allow_origin="*"') launch_new_instance()
def run(self): from IPython.terminal.ipapp import launch_new_instance sys.argv[1:] = [] warnings.filterwarnings("ignore", module = "zmq.*") sys.argv.append("notebook") sys.argv.append("--IPKernelApp.pylab='inline'") sys.argv.append("--NotebookApp.ip=0.0.0.0") sys.argv.append("--NotebookApp.open_browser=False") sys.argv.append('--NotebookApp.allow_origin="*"') #sys.argv.append('--NotebookApp.port_retries=0') launch_new_instance()
def run(self): from IPython.terminal.ipapp import launch_new_instance sys.argv[1:] = [] warnings.filterwarnings("ignore", module="zmq.*") sys.argv.append("notebook") sys.argv.append("--IPKernelApp.pylab='inline'") sys.argv.append("--NotebookApp.ip=0.0.0.0") sys.argv.append("--NotebookApp.open_browser=False") sys.argv.append('--NotebookApp.allow_origin="*"') #sys.argv.append('--NotebookApp.port_retries=0') launch_new_instance()
def start_ipython(argv=None, **kwargs): """Launch a normal IPython instance (as opposed to embedded) `IPython.embed()` puts a shell in a particular calling scope, such as a function or method for debugging purposes, which is often not desirable. `start_ipython()` does full, regular IPython initialization, including loading startup files, configuration, etc. much of which is skipped by `embed()`. This is a public API method, and will survive implementation changes. Parameters ---------- argv : list or None, optional If unspecified or None, IPython will parse command-line options from sys.argv. To prevent any command-line parsing, pass an empty list: `argv=[]`. user_ns : dict, optional specify this dictionary to initialize the IPython user namespace with particular values. kwargs : various, optional Any other kwargs will be passed to the Application constructor, such as `config`. """ from IPython.terminal.ipapp import launch_new_instance return launch_new_instance(argv=argv, **kwargs)
def start_kernel(argv=None, **kwargs): """Launch a normal IPython kernel instance (as opposed to embedded) `IPython.embed_kernel()` puts a shell in a particular calling scope, such as a function or method for debugging purposes, which is often not desirable. `start_kernel()` does full, regular IPython initialization, including loading startup files, configuration, etc. much of which is skipped by `embed()`. Parameters ---------- argv : list or None, optional If unspecified or None, IPython will parse command-line options from sys.argv. To prevent any command-line parsing, pass an empty list: `argv=[]`. user_ns : dict, optional specify this dictionary to initialize the IPython user namespace with particular values. **kwargs : various, optional Any other kwargs will be passed to the Application constructor, such as `config`. """ import warnings warnings.warn( "start_kernel is deprecated since IPython 8.0, use from `ipykernel.kernelapp.launch_new_instance`", DeprecationWarning, stacklevel=2, ) from ipykernel.kernelapp import launch_new_instance return launch_new_instance(argv=argv, **kwargs)
def attach_session(session, profile='default'): """ Start a terminal app attached to a notebook """ from IPython.terminal.ipapp import launch_new_instance kernel = 'kernel-{0}.json'.format(session['kernel']['id']) # TODO support other submodules like qtconsole argv = ['console', '--existing', kernel, '--profile={0}'.format(profile)] return launch_new_instance(argv=argv)
def attach_session(session, profile="default"): """ Start a terminal app attached to a notebook """ from IPython.terminal.ipapp import launch_new_instance kernel = "kernel-{0}.json".format(session["kernel"]["id"]) # TODO support other submodules like qtconsole argv = ["console", "--existing", kernel, "--profile={0}".format(profile)] return launch_new_instance(argv=argv)
def run(qt=False): # overwrite the original IPython Qt widget with our own so we can put a # customized banner. IPython may have been installed without Qt support so we # protect this code against an import error try: from IPython.utils.traitlets import Unicode from IPython.qt.console.rich_ipython_widget import RichIPythonWidget class ITangoConsole(RichIPythonWidget): banner = Unicode(config=True) def _banner_default(self): config = get_config() return config.ITangoConsole.banner import IPython.qt.console.qtconsoleapp IPythonQtConsoleApp = IPython.qt.console.qtconsoleapp.IPythonQtConsoleApp IPythonQtConsoleApp.widget_factory = ITangoConsole except ImportError: pass argv = sys.argv try: for i, arg in enumerate(argv[:1]): if arg.startswith('--profile='): break else: argv.append("--profile=tango") except: pass if qt: if not 'qtconsole' in argv: argv.insert(1, 'qtconsole') argv.append('--pylab=inline') launch_new_instance()
def run(qt=False): argv = sys.argv if not is_installed(): install(verbose=False) try: for i, arg in enumerate(argv[:1]): if arg.startswith('--profile='): break else: argv.append("--profile=tango") except: pass if qt: patch_qt_console() if 'qtconsole' not in argv: argv.insert(1, 'qtconsole') argv.append('--pylab=inline') launch_new_instance()
def _banner_default(self): config = get_config() return config.FrontendWidget.banner IPythonQtConsoleApp.widget_factory = SpockConsole except ImportError: pass try: check_requirements() except exception.SpockMissingRequirement, requirement: print str(requirement) sys.exit(-1) except exception.SpockMissingRecommended, recommended: print str(recommended) prepare_input_handler() prepare_cmdline() launch_new_instance() # TODO: Temporary solution, available while Taurus3 is being supported. try: from taurus.core.util.log import _DEPRECATION_COUNT from taurus import info info('\n*********************\n%s', _DEPRECATION_COUNT.pretty()) except: pass
def ipython(): """Start IPython.""" os.environ['PYTHONPATH'] = ':'.join(sys.path) from IPython.terminal.ipapp import launch_new_instance sys.exit(launch_new_instance(argv=[]))
import os, sys from IPython.terminal.ipapp import launch_new_instance from IPython.lib import passwd import warnings # set the password you want to use notebook_password = "******" sys.argv.append("notebook") sys.argv.append("--IPKernelApp.pylab='inline'") sys.argv.append("--NotebookApp.ip='*'") sys.argv.append("--NotebookApp.port=" + os.environ["ASPNETCORE_PORT"]) sys.argv.append("--NotebookApp.open_browser=False") sys.argv.append("--NotebookApp.notebook_dir=./notebooks") sys.argv.append("--NotebookApp.password=" + passwd(notebook_password)) launch_new_instance()
def notebook(): """Start IPython notebook.""" os.environ['PYTHONPATH'] = ':'.join(sys.path) sys.exit(launch_new_instance(argv=['notebook']))
def ipython(): """Start IPython.""" os.environ['PYTHONPATH'] = ':'.join(sys.path) sys.exit(launch_new_instance(argv=[]))