Dav
Dav

Reputation: 1

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. 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

Upvotes: 0

Views: 1011

Answers (1)

Jill Cheng
Jill Cheng

Reputation: 10372

Reason: The Python environment you are currently using in Jupyter in VSCode is not the environment where the module "rpy2" is installed.

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.

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.

enter image description here

Reference: Environment in VSCode and Jupyter notebook in VSCode.

Upvotes: 1

Related Questions