4

我有以下项目布局:

. my-project
|- pyproject.toml
|- poetry.lock
|- .jupyter
|  '- jupyter_notebook_config.py
|- kernels
|  '- R-renv
|     '- kernel.json
|- .renv
|- renv.lock
|- .Rprofile
'- # other stuff

IRkernel使用以下命令安装在 renv 中:

R -e 'install.packages("renv"); renv::activate(); renv::install("IRkernel"); IRkernel::installspec(); renv::snapshot(type = "all")'

Jupyterlab 通过 Poetry 安装。

[tool.poetry]
name = "my-project"
version = "0.1.0"

[tool.poetry.dependencies]
python = "^3.9"

[tool.poetry.dev-dependencies]
jupyterlab = "^3.2.8"
jupytext = "^1.13.6"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

jupyter_notebook_config.py中,我有:

c.NotebookApp.contents_manager_class="jupytext.TextFileContentsManager"
c.NotebookApp.notebook_dir = '/Users/X/Code/my-project/kernels' # absolute directory for debugging.
c.ContentsManager.default_jupytext_formats = ".ipynb,.Rmd"

kernel.json中,我有:

{"argv": ["R", "--slave", "-e", "IRkernel::main()", "--args", "{connection_file}"],
 "display_name":"R renv",
 "language":"R"
}

基于这个答案

但是,Jupyter 似乎没有选择内核:

❯ poetry run jupyter kernelspec list
Available kernels:
  ir         /Users/varun/Library/Jupyter/kernels/ir
  python3    /Users/varun/Library/Caches/pypoetry/virtualenvs/sg-data-analysis-ywZVJcuX-py3.9/share/jupyter/kernels/python3

如果我尝试poetry run jupyter notebook打开文件时会遇到错误.Rmd,因为它抱怨找不到 IRkernel,这与kernelspec list.

有没有办法可以将基于 Poetry 的 Jupyter 指向基于 renv 的 IRkernel,理想情况下无需修改项目目录之外的任何文件?

4

0 回答 0