Forums

error with rpy2

I'm trying to install rpy2 in my virtual environment and I get this error message. Can anyone help me figure out how to use rpy2.robjects in my flask app?

 In file included from /usr/share/R/include/Rdefines.h:25:0,
                     from ./rpy/rinterface/r_utils.c:23:
    /usr/share/R/include/R_ext/Memory.h:40:1: warning: function declaration isnt a prototype [-Wstrict-prototypes]
     int R_gc_running();
     ^
    In file included from /usr/share/R/include/Rdefines.h:29:0,
                     from ./rpy/rinterface/r_utils.c:23:
    /usr/share/R/include/Rinternals.h:719:1: warning: function declaration isnt a prototype [-Wstrict-prototypes]
     const char *R_curErrorBuf();
     ^
    ./rpy/rinterface/r_utils.c:24:31: fatal error: R_ext/Rallocators.h: No such file or directory
     #include <R_ext/Rallocators.h>
                                   ^
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/home/yoonk0/.virtualenvs/deploy/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-cBTFIy/rpy2/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-n50S5_-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/yoonk0/.virtualenvs/deploy/include/site/py
thon2.7/rpy2" failed with error code 1 in /tmp/pip-build-cBTFIy/rpy2/

[edit by admin: formatting]

I think the problem is that the latest version of the rpy2 library requires a more recent version of R than the one we have installed on our servers. If you install version 2.5.2 (ie. pip install rpy2==2.5.2) then it should work.

Thanks! can I use rpy2 2.5.2 when my program's originally written with the latest version of rpy2?

Hmm, good question. To be honest, I don't know the answer. The fact that we have an older version of R installed suggests that it might not... But still, it should only take a few moments to install the older version, so the best way to find out may just be to try it and see :-)

I installed rpy2 2.5.2 and I get a different error :( Is this because of the version? :

Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection
In addition: Warning message:
In readChar(con, 5L, useBytes = TRUE) :
  cannot open compressed file 'application/data/model.rdata', probable reason 'No such file or directory'
Traceback (most recent call last):
  File "/var/www/yoonk0_pythonanywhere_com_wsgi.py", line 88, in <module>
    from flask_app import app as application
  File "/home/yoonk0/oncology/flask_app.py", line 2, in <module>
    from application import app
  File "/home/yoonk0/oncology/application/__init__.py", line 11, in <module>
    fr.file_loader()
  File "/home/yoonk0/oncology/application/fileReader.py", line 17, in file_loader
    robjects.r['load'](self.filename)
  File "/home/yoonk0/.virtualenvs/deploy/local/lib/python2.7/site-packages/rpy2/robjects/functions.py", line 170, in __
call__
    return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs)
  File "/home/yoonk0/.virtualenvs/deploy/local/lib/python2.7/site-packages/rpy2/robjects/functions.py", line 100, in __
call__
    res = super(Function, self).__call__(*new_args, **new_kwargs)
rpy2.rinterface.RRuntimeError: Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection

[edit by admin: formatting]

I'm not sure. It might be, but it might simply be that the file can't be found. Are you using a full path to the file, eg. /home/yoonk0/something/somethingelse?

Oh it was the path. It's working now. Thanks so much!!

Great! Thanks for confirming.