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.

1
  • Command lines in jupyter -notebook apply to the Python session that runs the server, not the kernel that processes the notebook code. Commented Nov 7, 2019 at 17:04

1 Answer 1

3

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

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.