Ipython config inside jupyterhub_config.py

Hello, Our JupyterHub 4.1.5 works very well with a few extensions enabled. I am having difficulties in offering system-wide extension configuration settings via ipython to users.

ipython_config

I have tried placing ipython_config.json in many different /etc/ and /usr/ directories mentioned in the official documentation and also directly in /profile_default/ to no avail. I have operated with $ipython create profile which produces a config file but most settings are inactive (commented).

I some cases the user’s Terminal command $ ipython locate returns a JSON empty value error in line 1 char 1, even though the file was manually and automatically verified in several ways. But the command always return the correct value profile_default.

jupyterhub_config.py

I have also tried in jupyterhub_config.py to work with this setting to no effect,
c.BaseIPythonApplication.extra_config_file = '/opt/conda/envs/jupyterhub/etc/jupyterhub/ipython_config.json'

We want to control certain default settings like alerts and initial presentation and activate autoclosingbrackets and autocomplete. Here is a sample that could serve to help me understand how to write the syntax of ipython configurations to jupyterhub_config.py

// from the file 
// ~/.jupyter/lab/user-settings/@jupyterlab/apputils-extension/themes/jupyterlab-settings
{
  "adaptive-theme": true
}

// Other format
{
  "@jupyterlab/apputils-extension:themes": {
      "adaptive-theme": true
},

I have studied several documents and commentaries including https://ipython.readthedocs.io/en/8.23.0/config/intro.html#setting-configurable-options

Using the approach mentioned there and applying it to the above sample. Would this following statement be a valid translation for use in jupyterhub_config.py?

c.LabApp.apputils-extension.themes.adaptive-theme = True

jupyterhub_config.py is only for the hub component. singleuser servers run in their own environment with their own configuration files.

JupyterLab/Notebook configuration typically needs to go into one of the paths listed when you run jupyter --paths in your singleuser server. It’s possible you’ve got multiple Python environments with Jupyter/IPython, so make sure you use the right one.

I’m not sure about IPython, but maybe someone else can chime in?

1 Like

Thanks @manics . Jupyter paths is pointing to /opt/conda/envs/jupyterhub/etc/jupyter/ among other. It contains potentially applicable json config files. I am using this to explore further.

Configuration

  • rhea, sudospawner, conda
  • batch created ~/.ipython/profile_default/ for use by all ipython kernels

IPython 8.22.2

From the Terminal or inside a user’s Jupyter cell, !ipython --debug --show-config builds a dynamic output. It confirms that

  1. The scripts inside ~/.ipython/personal_default/startup/ are executed
  2. The config file /opt/conda/envs/jupyterhub/etc/ipython/ipython_config.py is loaded by default (if available there or in a number of other locations)

One ‘extra’ config file like .json can be loaded with ipython_config.py if one uses in jupyterhub_config.py this setting
c.BaseIPythonApplication.extra_config_file = '/path/to/ipython_config.json'

When a user executes ipython init resp. ipython profile create, the ipython_kernel_config.py file is created but it was not loaded in tests.

A problem loading extension configurations in the ipython_config files occurs still when using Python 3.11, even if the kernel was configured with "-X", "frozen_modules=off":

[TerminalIPythonApp] WARNING | Error in loading extension: ...
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
ModuleNotFoundError: No module named ... 

Possible solution: downgrading to Python 3.10

The error loading an extension was caused because I used a wrong description. The solution was to use a naming of the jupyterlab extension that was different than any name mentioned in the output of jupyter labextension list