简体   繁体   English

如何使用 python 命令行标志启动 Jupyter Notebook?

[英]How to launch Jupyter Notebook with python command line flags?

I want to disable hash randomization for a particular Jupyter notebook.我想为特定的 Jupyter 笔记本禁用 hash 随机化。 For a regular script, I do this via the python -R flag.对于常规脚本,我通过python -R标志执行此操作。 How can I achieve the same thing when running jupter-notebook ?运行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.当然,我可以通过设置PYTHONHASHSEED环境变量来实现这个特定目标,但我想通过标志来实现,因为它更灵活。

It can be done by either editing the kernel.json file or registering new kernel with changed kernel.json file. 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. kernel.json包含argv属性,该属性本质上是运行 python 的命令。

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

Editing existing kernel.json file编辑现有kernel.json文件

You can find your kernel.json by running:您可以通过运行以下命令找到您的kernel.json

→ 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销售定制 kernel

You can use the command from previous solution to find the existing kernel.json您可以使用先前解决方案中的命令来查找现有的kernel.json

then install the new kernel:然后安装新的 kernel:

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

Find your python3_custom location with找到您的python3_custom位置

jupyter kernelspec list

and edit the kernel.json there并在那里编辑kernel.json

Jupyterlab kernel docsJupyterlab kernel 文档

registering kernels in ipython/jupyter notebook - kernel.json在 ipython/jupyter 笔记本中注册内核 - kernel.json

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM