Rpy2 error wac-a-mole: R_USER not defined

老子叫甜甜 提交于 2019-11-27 21:26:59

问题


I'm running Python (x,y) 2.7 on windows 7 32 bit and R version 3.1.0. I've been trying to install Rpy2 and have been getting many errors. I finally found this site which has pre-compiled python modules for windows http://www.lfd.uci.edu/~gohlke/pythonlibs/, so I downloaded rpy2‑2.4.2.win32‑py2.7.exe. When I did this and tried

import rpy2.robjects as robjects

I had an error saying it could not find R_HOME, so I updated my path variables. This was fixed, but then I got an error saying it could not find R_USER. Once again, I updated my PYTHONPATH variables based on SO responses. This didn't work, and so I'm stuck. I've updated my PYTHONPATH both inside Spyder and also in my system variables, but still no luck. Does anyone know what could be going on? This is the error I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\rpy2\robjects\__init__.py", line 18, in <module>
    from rpy2.robjects.robject import RObjectMixin, RObject
  File "C:\Python27\lib\site-packages\rpy2\robjects\robject.py", line 5, in <module>
    rpy2.rinterface.initr()
RuntimeError: R_USER not defined.

This is what my PYTHONPATH includes:

C:\Python27\Lib\site-packages\rpy2;C:\Program Files\R\R-3.1.0\bin\i386;C:\Python27\Lib\site-packages\rpy2\robjects

This is what my PATH includes:

C:\Python27\Lib\site-packages\PyQt4;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;c:\Program Files\Intel\DMIX;C:\Program Files\Intel\Services\IPT\;C:\Python27;C:\Python27\DLLs;C:\Python27\Scripts;C:\Python27\Lib\site-packages\vtk;C:\Python27\gnuplot\binary;C:\Program Files\pythonxy\SciTE-3.1.0;C:\Program Files\pythonxy\console;C:\MinGW32-xy\bin;C:\Program Files\R\R-3.1.0\bin;C:\MinGW32-xy\mingw32\bin;C:\MinGW32-xy\bin

Thanks for any help you can provide!


回答1:


You need to set the R_USER environment variable, e.g. to the username of the Windows account you use. See also this quote from this link:

1) Add the path to R.dll to my PATH variable (I went to the 32-bit directory) 2) Add an environment variable R_HOME (C:\Program Files\R\R-2.12.1 for me) 3) Add an environment variable R_USER (simply my username in Windows).



来源:https://stackoverflow.com/questions/24414540/rpy2-error-wac-a-mole-r-user-not-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!