问题
I want to disable the randomization of Python's hash function. According to this thread (Unable to see or modify value of PYTHONHASHSEED through a module), setting PYTHONHASHSEED by setting os.environ['PYTHONHASHSEED']
at runtime does not work. How can I set PYTHONHASHSEED to a fixed value when I run Jupyter Notebook?
回答1:
You can try to modify the kernel.json
and add the line "env": {"PYTHONHASHSEED":"0"}
.
The file is located in your python-folder or virtual environment at:
[venv|python-folder]/share/jupyter/kernels/python3/kernel.json
kernel.json:
{
"argv": [
"python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Python 3",
"language": "python",
"env": {"PYTHONHASHSEED":"0"}
}
That solves the issue for me.
回答2:
Try to add
%env PYTHONHASHSEED=0
into your code. More information:
https://ipython.readthedocs.io/en/stable/interactive/magics.html?highlight=env#magic-env
来源:https://stackoverflow.com/questions/58067359/is-there-a-way-to-set-pythonhashseed-for-a-jupyter-notebook-session