How to Reset Ipython/Jupyter Profile After Upgrade to 'Factory' Defaults

How to reset iPython/Jupyter profile after upgrade to 'factory' defaults?

Fixed!

I'm guessing there is a directed-ness to the Jupyter system (python, ipython, jupyter, a browser) where I have to reset parts in order.

I will take a guess and put these in a specific order. (Others can reorder if this turns out meaningful):

  1. Update python packages
  2. Created a new iPython profile: $ ipython profile create foo
  3. Rename profile_foo to profile_default
  4. Initialize a Jupyter profile: $ jupyter notebook --generate-config
  5. Clear the cache in your browser **:

    • Chrome (v52),

      • "Cookies and other site data"
      • "Cached images and files"
    • Firefox (v47),

      • "Offline web content and user data"
      • "Cached web content"

CAUTION: I'm assuming any existing iPython/Jupyter settings are not an issue, because the goal is to restore to factory, so to speak. And, I'm also assuming you're trying not to delete your saved passwords or bookmarks or history during a browser cache clearing step.

** I'm not clear which cache settings specifically include iPython/Jupyter data. These are only the settings I used and the problem was fixed.

Change IPython/Jupyter notebook working directory

jupyter notebook --help-all could be of help:

--notebook-dir=<Unicode> (NotebookManager.notebook_dir)
Default: u'/Users/me/ipynbs'
The directory to use for notebooks.

For example:

jupyter notebook --notebook-dir=/Users/yourname/folder1/folder2/

You can of course set it in your profiles if needed, you might need to escape backslash in Windows.

Note that this will override whatever path you might have set in a jupyter_notebook_config.py file. (Where you can set a variable c.NotebookApp.notebook_dir that will be your default startup location.)

How to change the Jupyter start-up folder

Jupyter Notebook and JupyterLab < 3.0

For old Jupyter Notebook interface installed with notebook package and run as jupyter notebook (see the next section for the identical interface installed with nbclassic and run with jupyter nbclassic, and for JupyterLab):

  1. Open cmd (or Anaconda Prompt) and run jupyter notebook --generate-config.

  2. This writes a file to C:\Users\username\.jupyter\jupyter_notebook_config.py.

  3. Browse to the file location and open it in an Editor

  4. Search for the following line in the file:
    #c.NotebookApp.notebook_dir = ''

  5. Replace by c.NotebookApp.notebook_dir = '/the/path/to/home/folder/'

    Make sure you use forward slashes in your path and use /home/user/ instead of ~/ for your home directory, backslashes could be used if placed in double quotes even if folder name contains spaces as such :
    "D:\yourUserName\Any Folder\More Folders\"

  6. Remove the # at the beginning of the line to allow the line to execute

JupyterLab >= 3, Jupyter Notebook Classic, and RetroLab

For recent nbclassic and JupyterLab >= 3 use c.ServerApp.root_dir instead of c.NotebookApp.notebook_dir (and jupyter server --generate-config instead of jupyter notebook --generate-config).

For context see migration guide and this question on differences between server and notebook.

How to change the default browser used by the ipython/jupyter notebook in Linux?

You can create jupyter_notebook_config.py by:

jupyter notebook --generate-config

Then you go to

~/.jupyter/jupyter_notebook_config.py

and change

# c.NotebookApp.browser = ''

to for example:

c.NotebookApp.browser = '/usr/bin/google-chrome %s'

You can choose which ever browser is installed. You'll find the path for example by typing which firefox
Do not forget to delete the #

Changing the default port for iPython notebook server / Jupyter

jupyter notebook --ip=0.0.0.0 --port=80 or
ipython notebook --ip=0.0.0.0 --port=80

is what i did to run ipython in my vagrant box. (Opened up the ports on the vagrant box to access it on my host mac)

usage: ipython [-h] [--certfile NOTEBOOKAPP.CERTFILE] [--ip NOTEBOOKAPP.IP]
[--pylab [NOTEBOOKAPP.PYLAB]]
[--log-level NOTEBOOKAPP.LOG_LEVEL]
[--port-retries NOTEBOOKAPP.PORT_RETRIES]
[--notebook-dir NOTEBOOKAPP.NOTEBOOK_DIR]
[--config NOTEBOOKAPP.CONFIG_FILE]
[--keyfile NOTEBOOKAPP.KEYFILE] [--port NOTEBOOKAPP.PORT]
[--transport KERNELMANAGER.TRANSPORT]
[--browser NOTEBOOKAPP.BROWSER] [--script] [-y] [--no-browser]
[--debug] [--no-mathjax] [--no-script] [--generate-config]

Incase the port is already occupied, see what's blocking it - inmy case it was an old instance of ipython which had not been terminated properly. I kiiled them all with this command

ps auxww | grep 'ipython' | awk '{print $2}' | xargs sudo kill -9

Mysteriously assigned constructor argument in iPython

Here is a correct dummy.py script without a mutable as default value for the argument:

class Dummy():
def __init__(self, others=None):
self._others = others or []
pass

def receive(self, value):
self._others.append(value)

@property
def others(self):
return self._others

Output:

created = []
received = ['something']


Related Topics



Leave a reply



Submit