有没有办法为Jupyter Notebook会话设置PYTHONHASHSEED?

时间:2019-09-23 17:23:38

标签: python jupyter-notebook environment-variables

我想禁用randomization of Python's hash function。根据该线程(Unable to see or modify value of PYTHONHASHSEED through a module),在运行时通过设置~ (user folder) ~/Documents ~/Documents/useanimal ~/Documents/useanimal/UseDog.java ~/Downloads ~/Downloads/animal ~/Downloads/animal/Dog.java 来设置PYTHONHASHSEED不起作用。运行Jupyter Notebook时如何将PYTHONHASHSEED设置为固定值?

2 个答案:

答案 0 :(得分:3)

您可以尝试修改kernel.json并添加行"env": {"PYTHONHASHSEED":"0"}。 该文件位于您的python文件夹或虚拟环境中,位于:

[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"}
}

那为我解决了这个问题。

答案 1 :(得分:-1)

尝试添加

  

%env PYTHONHASHSEED = 0

输入您的代码。 详细信息:

https://ipython.readthedocs.io/en/stable/interactive/magics.html?highlight=env#magic-env