Search code examples
pythonrpy2

Unable to import rpy2, VSCode in WSL windows subsytem for linux


Looking for help on using rpy2 in python script with vscode from WSL. I can't get the import to work.

If i try to run the following code:

import rpy2

print(rpy2.__version__)

I get the following AttributeError:

AttributeError: partially initialized module 'rpy2' has no attribute '__version__' (most likely due to a circular import)

If I try to import rpy2.rpackages, I get the following error:

ModuleNotFoundError: No module named 'rpy2.rpackages'; 'rpy2' is not a package

I have successfully installed rpy2 through the bash terminal on VSCode with pip as shown in the below screenshot:

enter image description here


Solution

  • There is no module or sub-package rpackages in rpy2, so the error message when trying to import it is expected.

    The error about a circular a partially initialized module is surprising. Do you happen to have a directory called rpy2 where you are running this from? Python would try to import that directory.