无法在 Google AI Platform 上使用 jupyter notebook 实例连接到 R 内核

Cannot connect to R kernel using jupyter notebook instance on Google AI Platform

当我按照此处的说明创建新实例时 https://cloud.google.com/architecture/data-science-with-r-on-gcp-eda,笔记本无法连接到 R 内核。它说正在初始化,然后连接然后断开连接。

当我通过 SSH 连接到服务器并调用 curl http://127.0.0.1:8080/api/kernelspecs 时,我得到以下输出。

{
    "default": "python3", 
    "kernelspecs": {
        "python3": {
            "name": "python3", 
            "spec": {
                "argv": [
                    "/opt/conda/bin/python", "-m","ipykernel_launcher", "-f", "{connection_file}"
                ], 
                "env": {}, 
                "display_name": "Python 3", 
                "language": "python", 
                "interrupt_mode": "signal", 
                "metadata": {"debugger": true}
            }, 
            "resources": {
                "logo-32x32": "/kernelspecs/python3/logo-32x32.png",
                "logo-64x64": "/kernelspecs/python3/logo-64x64.png"
            }
        }, 
        "ir": {
            "name": "ir", 
            "spec": {
                "argv": [
                    "/usr/lib/R/bin/R", "--slave", "-e", "IRkernel::main()", "--args", "{connection_file}"
                ], 
                "env": {}, 
                "display_name": "R", 
                "language": "R", 
                "interrupt_mode": "signal", 
                "metadata": {}
            }, 
            "resources": {
                "kernel.js": "/kernelspecs/ir/kernel.js", 
                "logo-64x64": "/kernelspecs/ir/logo-64x64.png"}
            }, 
            "conda-root-py": {
                "name": "conda-root-py", 
                "spec": {
                    "argv": ["/opt/conda/bin/python", "-m", "ipykernel_launcher", "-f", "{connection_file}"
                    ], 
                    "env": {}, 
                    "display_name": 
                    "Python [conda env:root] *", 
                    "language": "python", 
                    "interrupt_mode": "signal", 
                    "metadata": {
                        "debugger": true, 
                        "conda_env_name": "root", 
                        "conda_env_path": "/opt/conda"
                    }
                }, 
                "resources": {
                    "logo-32x32": "/kernelspecs/conda-root-py/logo-32x32.png", 
                    "logo-64x64": "/kernelspecs/conda-root-py/logo-64x64.png"
                }
            }
       }
}root@r-ma5832xxxxxxxxx

这对于使用 R4.0 环境选项创建的实例是否正确?

当我检查服务器日志时,我发现了这个:

Error: package ‘IRkernel’ was installed before R 4.0.0: please re-install it

我打开了一个连接到服务器的 ssh 控制台并 cd 到 /etc/R,然后通过键入 'R'.

启动了 R

然后我尝试按照此处的说明使用 install.packages('IRkernel') 安装软件包:https://github.com/IRkernel/IRkernel only I ran into a whole lot of missing dependencies. I tried to update my version of R by following the instructions here: https://cran.r-project.org/bin/linux/debian/#debian-buster-stable 但事实证明我是最新的。唯一剩下的就是更新我所有的包。我按照 cran 网站上的说明进行操作,然后回到我的 jupyter notebook 并可以连接到内核。

最后,我所要做的就是 运行 在我服务器上的 R 中执行下面的命令来解锁内核。

update.packages(lib.loc="/usr/local/lib/R/site-library", ask = FALSE, checkBuilt = TRUE, Ncpus = 16)