1

I've asked the following question, some time ago: Preloading the Jupyter Notebook with specific classes/functions

This works great when I start the interpreter with ipython --profile=DOS in my terminal. I have all the predefined functionalities available in the interpreter.

My question is, how do I load this into a jupyter notebook? So far, I can only load python2 or python 3.

Say a jupyter notebook configuration looks like

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "test\n"
     ]
    }
   ],
   "source": [
    "print(\"test\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}

Can I use a configuration where it uses ipython3 --profile=DOS, resulting in loading the predefined functionalities?

1 Answer 1

3

You have to create a customized kernelspecs folder under one of the JUPYTER_PATHs, as demonstrated in the documentation.

If you do want to change the IPython kernel’s profile, you can’t do this at the server command-line anymore. Kernel arguments must be changed by modifying the kernelspec. You can do this without relaunching the server. Kernelspec changes take effect every time you start a new kernel.

For example, add the --profile=DOS option to a custom kernelspec under .../kernels/mycustomDOSpython/kernel.json, where "mycustomDOSpython" is your new kernel's name, which will automatically appear on the "New" dropdown button of the jupyter notebook server.

{
 "argv": ["python3", "-m", "ipykernel",
          "--profile=DOS",
          "-f", "{connection_file}"],
 "display_name": "Python 3 with profile DOS",
 "language": "python"
}

Then, in your .ipynb notebook file, change the "name" of the "kernelspec" correspondingly:

"kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "mycustomDOSpython"
  },
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.