Is there a way to set PYTHONHASHSEED for a Jupyter Notebook session?

浪子不回头ぞ 提交于 2020-06-28 07:01:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!