How to setup environment variable R_user to use rpy2 in python

前端 未结 6 1187
暗喜
暗喜 2020-11-28 08:43

I \'m unable to run rpy2 in python.

with this code

 import rpy2.robjects as robjects

Here\'s the full exceptions:


R

6条回答
  •  猫巷女王i
    2020-11-28 09:19

    If you want to use Python with rpy2 but you also want to keep using your RStudio, don't forget to add RStudio to your path as well, or you'll get some path issues.

    You can change your paths according to @user3758274:

    Change Path for R computer-> property -> advanced and system setting -> environment variables in the user variable field add C:\Program Files\R\R-3.0.2\bin\x64 (my system is windows 64bit) to path

    In the system variable field add two new variables

    R_HOME    c:\program files\r\r-3.0.2
    
    R_USER    C:\Users\"your user name"\Anaconda\Lib\site-packages\rpy2
    

    But then add also RStudio to your R_USER system variable, so you'll get:

    R_USER    C:\Program Files\RStudio\bin;C:\Users\"your user name"\Anaconda\Lib\site-packages\rpy2
    

提交回复
热议问题