优雅地选取jupyter内核

vscode里的jupyter notebook我用着很满意,但是有一个小问题。

我安装了多个python环境还有一个julia的解释器,每次打开一个笔记本文件,总是会让我指定一个内核运行:

这种情况当然敲一个键就完事了,但是次数多了难免会让人厌倦。于是我在网上找了一圈,找到了官方给出的[解决方案](https://github.com/microsoft/vscode/issues/130946#issuecomment-1899389049)

Solutions

1. Hide all of the Python environments except the one you need

  • If you have n python environments and you only use one, then hide all of the others.
  • If you have just Jupyter and Python extension, then the remaining Python env will be automatically selected (however if you have other remote jupyter kernels, or other extensions that contribute kernels, then this will not get selected automatically). Please see solution 2.
  • Open a Jupyter ntoebook (to ensure the Jupyter extension gets activated)
  • Open your settings.json file
  • Add the setting "jupyter.kernels.excludePythonEnvironments": [...] and add the environments you wish to hide.

See here microsoft/vscode-jupyter#13032 (comment)

2. Install the extension Default Python Kernels for Jupyter Notebooks

From here on, all notebooks opened will have the active Python environment selected as the kernel.
You can change the Active Python Environment for your workspace/globally using the command Python: Select Interpreter

You can find more information on the read me of the above extension.

第一种方案是排除其他的内核选择,但是其他的内核还要用,这种方案就不能用,第二种是安装一个插件就好了。

插件会自动选择当前活跃的内核,避免了多次选取的麻烦,问题圆满解决。


优雅地选取jupyter内核
https://silenzio111.github.io/2024/09/03/kernelchoice/
作者
silenzio
发布于
2024年9月3日
许可协议