Windows 7 で Python 2.7 を実行しています。まず、R と RTools をインストールし、次の環境変数を変更しました。
RHOME: C:\Program Files\R\R-2.15.2
R_HOME: C:\Program Files\R\R-2.15.2
R_USER: C:\Users\username\Documents
そして、次のディレクトリを PATH に追加しました。
C:\Program Files\R\R-2.15.\bin\i386; C:\Rtools\bin
次に、RPy2 をバイナリ実行可能ファイル (こちら) からインストールしました。
Python で RPY2 を実行すると、次のエラーが発生します。
Traceback (most recent call last):
File "<string>", line 254, in run_nodebug
File "C:\Python27\blaise automation.py", line 14, in <module>
import rpy2.robjects as robjects
File "C:\Python27\lib\site-packages\rpy2\robjects\__init__.py", line 14, in <module>
import rpy2.rinterface as rinterface
File "C:\Python27\lib\site-packages\rpy2\rinterface\__init__.py", line 28, in <module>
"or install the win32 package.")
RuntimeError: No environment variable R_HOME could be found, calling the command 'R RHOME' does not return anything, and unable to import win32api or win32con, both of which being needed to retrieve where is R from the registry. You should either specify R_HOME or install the win32 package.
私はHOURSのためにこれに取り組んできました。誰かがそれを解決する方法を知っていますか?
私のコード:
import rpy2.robjects as robjects
import pywin
def main():
robjects.r("require(foreign)")