0

I want to disable hash randomization for a particular Jupyter notebook. For a regular script, I do this via the python -R flag. How can I achieve the same thing when running jupter-notebook?

Of course I can achieve this particular goal via setting the PYTHONHASHSEED environmental variable but I would like to do it via the flag since it is more flexible.

Chris_Rands
  • 38,994
  • 14
  • 83
  • 119
  • Command lines in `jupyter -notebook` apply to the Python session that runs the server, not the kernel that processes the notebook code. – hpaulj Nov 07 '19 at 17:04

1 Answers1

2

It can be done by either editing the kernel.json file or registering new kernel with changed kernel.json file.

kernel.json contains argv attribute that essentially a command to run python.

{
 "argv": [
  "python",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "Python 3",
 "language": "python"
}

Editing existing kernel.json file

You can find your kernel.json by running:

→ jupyter kernelspec list

Available kernels:
  python3           /home/user/.local/share/virtualenvs/jupyter/share/jupyter/kernels/python3

You can edit it to your liking.

Insalling custom kernel

You can use the command from previous solution to find the existing kernel.json

then install the new kernel:

jupyter kernelspec install  /home/user/.local/share/virtualenvs/jupyter/share/jupyter/kernels/python3 --name=python3_custom --user

Find your python3_custom location with

jupyter kernelspec list

and edit the kernel.json there

Jupyterlab kernel docs

registering kernels in ipython/jupyter notebook - kernel.json

Kamil Niski
  • 4,580
  • 1
  • 11
  • 24