Execute Python script within Jupyter notebook using a specific virtualenv

Here’s what worked for me (non conda python): (MacOS, brew version of python. if you are working with system python, you may (will) need prepend each command with sudo) First activate virtualenv. If starting afresh then, e.g., you could use virtualenvwrapper: $ pip install virtualenvwrapper $ mkvirtualenv -p python2 py2env $ workon py2env # This … Read more

Plotly chart not showing in Jupyter notebook

You need to change init_notebook_mode call and remove connected=True, if you want to work in offline mode. Such that: # Import the necessaries libraries import plotly.offline as pyo import plotly.graph_objs as go # Set notebook mode to work in offline pyo.init_notebook_mode() # Create traces trace0 = go.Scatter( x=[1, 2, 3, 4], y=[10, 15, 13, 17] … Read more

JupyterLab autocomplete without tab

The jupyterlab-lsp extension offers this as an opt-in feature. After installing the extension in JupyterLab 3.0+ (which is two part: jupyterlab-lsp and the language server of your choice – see the linked instructions) you need to enable it in Advanced Settings Editor → Code Completion → continuousHinting: Disclaimer: I am one of the authors. This … Read more

Overwrite previous output in jupyter notebook

@cel is right: ipython notebook clear cell output in code Using the clear_output() gives makes your Notebook have the jitters, though. I recommend using the display() function as well, like this (Python 2.7): from random import uniform import time from IPython.display import display, clear_output def black_box(): i = 1 while True: clear_output(wait=True) display(‘Iteration ‘+str(i)+’ Score: … Read more

How do I set up Jupyter/IPython Notebook for Django?

Install django-extensions from https://github.com/django-extensions/django-extensions/blob/master/docs/index.rst pip install django-extensions Change your settings file to include ‘django-extensions’ INSTALLED_APPS += [‘django_extensions’] Run your Django server like this: python manage.py shell_plus –notebook alter to suit, and run this in your first cell import os, sys PWD = os.getenv(‘PWD’) os.chdir(PWD) sys.path.insert(0, os.getenv(‘PWD’)) os.environ.setdefault(“DJANGO_SETTINGS_MODULE”, “local_settings.py”) import django django.setup() Now you should be … Read more

Simple way to visualize a TensorFlow graph in Jupyter?

Here’s a recipe I copied from one of Alex Mordvintsev deep dream notebook at some point from IPython.display import clear_output, Image, display, HTML import numpy as np def strip_consts(graph_def, max_const_size=32): “””Strip large constant values from graph_def.””” strip_def = tf.GraphDef() for n0 in graph_def.node: n = strip_def.node.add() n.MergeFrom(n0) if n.op == ‘Const’: tensor = n.attr[‘value’].tensor size … Read more