VS Code Notebook 和 JupyterLab 都是用于数据科学和机器学习的工具,它们都提供了交互式计算环境和数据可视化功能。
然而,它们有一些不同之处:
Visual Studio Code for the Web
Opening a project
Connecting to a remote Jupyter server from vscode.dev · microsoft/vscode-jupyter Wiki (github.com)
Jupyter Notebooks on the web (visualstudio.com)
如果使用浏览器,用https://vscode.dev/github/..
的方式,例如https://vscode.dev/github/JabuMlDev/Speaker-VGG-CCT
,想要运行notebook,需要一个notebook服务器链接(server url)
以本地连接为例,可以参考:starting your own server
jupyter notebook
后得到的url
是对于vscode web是不可用的jupyter notebook --no-browser --NotebookApp.allow_origin='*'
How to get the current jupyter notebook servers in python? - Stack Overflow
在命令行中执行 jupyter notebook
启动服务后,命令行会返回给你一个url
如果您想在notebook 中用python查看这个连接:
from notebook import notebookapp
servers = list(notebookapp.list_running_servers())
print(servers)
[{'base_url': '/', 'hostname': 'localhost', 'notebook_dir': 'D:\\repos\\CCSER\\emotion-recognition-using-speech', 'password': False, 'pid': 9684, 'port': 8888, 'secure': False, 'sock': '', 'token': 'ac4e4b1ed699db8088af6cce640998ec3882b06454976dfb', 'url': 'http://localhost:8888/'}]
这有局限性,vscode启动的notebook只会返回空列表
使用命令行jupyter notebook list
效果类似
但是用vscode连接到jupyter notebook
不容易查到运行的notebook实例的url
.py
文件的时候就可以使用jupyter notebook的部分功能
.py
创建一个临时的.ipynb
但是目前只有vscode支持PIW
JNN
.py
下和.ipynb
(PIW,JNN)下快捷键不通用notebook本身有一套快捷键逻辑,而且分为2中模式
直接配置:打开command palette,输入 open keyboard shortcuts
,搜索关键字
本人更新换直接全局的快捷键,下面描述以下本人自用的快捷键
keybindings.json modify
配置文件keybindings.json
,可以使用ctrl+p
输入打开
$env:APPDATA\code\user
快捷键命令格式:notebook.cell.
{
"key": "ctrl+m ctrl+m",
"command": "notebook.cell.changeToMarkdown",
"when": "notebookEditorFocused && activeEditor == 'workbench.editor.notebook' && notebookCellType == 'code'"
},
{
"key": "ctrl+m ctrl+c",
"command": "notebook.cell.changeToCode",
"when": "notebookEditorFocused && !notebookOutputFocused && activeEditor == 'workbench.editor.notebook' && notebookCellType == 'markup'"
},
{
"key": "shift+alt+b",
"command": "notebook.cell.insertCodeCellBelow"
},
{
"key": "shift+alt+a",
"command": "notebook.cell.insertCodeCellAbove"
},
ctrl+m ctrl+m
将一个code cell转换为markdown cellctrl+m ctrl+c
将一个cell转换为code celljetbrains intelligent IDEA
的notebook向上/向下插入一个代码cellkeybingdings.json
不会使默认的快捷键失效,但是这不是说不和其他快捷键冲突cell分割和合并
{
"key": "ctrl+shift+-",
"command": "notebook.cell.split",
"when": "editorTextFocus && inputFocus && notebookEditorFocused && !notebookOutputFocused"
},
删除单元格
{
"key": "ctrl+shift+backspace",
"command": "notebook.cell.delete",
"when": "notebookEditorFocused && !notebookOutputFocused"
},
清除单元格输出(以下二选一即可,也可以都保留)
{
"key": "alt+backspace",
"command": "notebook.cell.clearOutputs",
"when": "notebookEditorFocused && !notebookOutputFocused"
},
{
"key": "alt+delete",
"command": "notebook.cell.clearOutputs",
"when": "notebookEditorFocused && !notebookOutputFocused"
},
运行当前cell
{
"key": "ctrl+k ctrl+c",
"command": "notebook.cell.execute",
"when": "notebookCellListFocused && notebookMissingKernelExtension && !notebookCellExecuting && notebookCellType == 'code' || notebookCellListFocused && !notebookCellExecuting && notebookCellType == 'code' && notebookKernelCount > 0 || notebookCellListFocused && !notebookCellExecuting && notebookCellType == 'code' && notebookKernelSourceCount > 0"
},
jupyter.
when
的配置:when clause contexts | Visual Studio Code Extension API