简体   繁体   English

在带有 Jupyter Notebook 的 Visual Studio Code 中使用 rpy2 不起作用

[英]using rpy2 in Visual Studio Code with Jupyter Notebook doesn't work

I use the first Line of Code below in normal Visual Studio Code Python and it works, but with the same Code in Jupyter Notebook comes error.我在正常的 Visual Studio 代码 Python 中使用下面的第一行代码并且它可以工作,但是在 Jupyter Notebook 中使用相同的代码会出现错误。 Can someone help me?有人能帮我吗? thanks.谢谢。

import rpy2.robjects as ro
%load_ext rpy2.ipython

r=ro.r
r.source("C:/RNN_Forecast/test1R.R")
p1=r.func1()
p2=r.func2()
print(p1)

These are the error messages这些是错误消息

Reason: The Python environment you are currently using in Jupyter in VSCode is not the environment where the module " rpy2 " is installed.原因:你目前在VSCode中Jupyter中使用的Python环境不是安装模块“ rpy2 ”的环境。

Solution: Please switch the Python interpreter in the upper right corner of Jupyter to the same as the interpreter in the lower left corner of VSCode.解决方法:请将 Jupyter 右上角的 Python 解释器切换到与 VSCode 左下角的解释器相同。

For example: using the environment named "tf", we can execute code in the terminal, when using the same environment, we can also execute code in Jupyter in VSCode.例如:使用名为“tf”的环境,我们可以在终端中执行代码,使用相同的环境时,我们也可以在VSCode中执行Jupyter中的代码。

在此处输入图像描述

Reference: Environment in VSCode and Jupyter notebook in VSCode .参考:VSCode 中的环境VSCode 中的 Jupyter 笔记本

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

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