4

I am trying to install the package rpy2 to use R with Python. But the Installation using pip install fails.

I am using R and Python with Microsoft Visual Studio 2017 on Windows 10. There are R and Python Tools for Visual Studio installed. I tried to install rpy2 from Visual Studio using python environments. But it fails.

I have also downloaded rpy2-2.9.5-cp37-cp37m-win_amd64.whl from lfd.uci.edu and tried to install it using cmd and pip install and it failed too.

I have also set the R-Home variable pointing to the R binaries of my R installation.

Commands I tried: pip install rpy2 (in Visual Studio)

pip install rpy2-2.9.5-cp37-cp37m-win_amd64.whl (using cmd)

The following error message appears when installing rpy2 within Visual Studio 2017:

----- "rpy2==3.0.5" wird installiert -----
Collecting rpy2==3.0.5
  Using cached https://files.pythonhosted.org/packages/c7/43/401afad8556bf92b08bd7d422cacac614b0e8dd2bce31848318bbcb18f48/rpy2-3.0.5.tar.gz
    ERROR: Command errored out with exit status 1:
     command: 'C:\Users\eisem\AppData\Local\Programs\Python\Python37-32\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\eisem\\AppData\\Local\\Temp\\pip-install-afwht5_8\\rpy2\\setup.py'"'"'; __file__='"'"'C:\\Users\\eisem\\AppData\\Local\\Temp\\pip-install-afwht5_8\\rpy2\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: C:\Users\eisem\AppData\Local\Temp\pip-install-afwht5_8\rpy2\
    Complete output (69 lines):
    warning: no previously-included files found matching 'setup.pyc'
    warning: no previously-included files matching 'yacctab.*' found under directory 'tests'
    warning: no previously-included files matching 'lextab.*' found under directory 'tests'
    warning: no previously-included files matching 'yacctab.*' found under directory 'examples'
    warning: no previously-included files matching 'lextab.*' found under directory 'examples'
    zip_safe flag not set; analyzing archive contents...
    pycparser.ply.__pycache__.lex.cpython-37: module references __file__
    pycparser.ply.__pycache__.lex.cpython-37: module MAY be using inspect.getsourcefile
    pycparser.ply.__pycache__.yacc.cpython-37: module references __file__
    pycparser.ply.__pycache__.yacc.cpython-37: module MAY be using inspect.getsourcefile
    pycparser.ply.__pycache__.yacc.cpython-37: module MAY be using inspect.stack
    pycparser.ply.__pycache__.ygen.cpython-37: module references __file__

    Installed c:\users\eisem\appdata\local\temp\pip-install-afwht5_8\rpy2\.eggs\pycparser-2.19-py3.7.egg
    Traceback (most recent call last):
      File "c:\users\eisem\appdata\local\temp\pip-install-afwht5_8\rpy2\.eggs\cffi-1.12.3-py3.7-win32.egg\cffi\cparser.py", line 294, in _parse
        ast = _get_parser().parse(fullcsource)
      File "c:\users\eisem\appdata\local\temp\pip-install-afwht5_8\rpy2\.eggs\pycparser-2.19-py3.7.egg\pycparser\c_parser.py", line 152, in parse
        debug=debuglevel)
      File "c:\users\eisem\appdata\local\temp\pip-install-afwht5_8\rpy2\.eggs\pycparser-2.19-py3.7.egg\pycparser\ply\yacc.py", line 331, in parse
        return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
      File "c:\users\eisem\appdata\local\temp\pip-install-afwht5_8\rpy2\.eggs\pycparser-2.19-py3.7.egg\pycparser\ply\yacc.py", line 1199, in parseopt_notrack
        tok = call_errorfunc(self.errorfunc, errtoken, self)
      File "c:\users\eisem\appdata\local\temp\pip-install-afwht5_8\rpy2\.eggs\pycparser-2.19-py3.7.egg\pycparser\ply\yacc.py", line 193, in call_errorfunc
        r = errorfunc(token)
      File "c:\users\eisem\appdata\local\temp\pip-install-afwht5_8\rpy2\.eggs\pycparser-2.19-py3.7.egg\pycparser\c_parser.py", line 1848, in p_error
        column=self.clex.find_tok_column(p)))
      File "c:\users\eisem\appdata\local\temp\pip-install-afwht5_8\rpy2\.eggs\pycparser-2.19-py3.7.egg\pycparser\plyparser.py", line 67, in _parse_error
        raise ParseError("%s: %s" % (coord, msg))
    pycparser.plyparser.ParseError: <cdef source string>:23:5: before: blah1

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\eisem\AppData\Local\Temp\pip-install-afwht5_8\rpy2\setup.py", line 184, in <module>
        'rpy2': ['doc/source/rpy2_logo.png', ]}
      File "C:\Users\eisem\AppData\Local\Programs\Python\Python37-32\lib\site-packages\setuptools\__init__.py", line 145, in setup
        return distutils.core.setup(**attrs)
      File "C:\Users\eisem\AppData\Local\Programs\Python\Python37-32\lib\distutils\core.py", line 108, in setup
        _setup_distribution = dist = klass(attrs)
      File "C:\Users\eisem\AppData\Local\Programs\Python\Python37-32\lib\site-packages\setuptools\dist.py", line 447, in __init__
        k: v for k, v in attrs.items()
      File "C:\Users\eisem\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py", line 292, in __init__
        self.finalize_options()
      File "C:\Users\eisem\AppData\Local\Programs\Python\Python37-32\lib\site-packages\setuptools\dist.py", line 739, in finalize_options
        ep.load()(self, ep.name, value)
      File "c:\users\eisem\appdata\local\temp\pip-install-afwht5_8\rpy2\.eggs\cffi-1.12.3-py3.7-win32.egg\cffi\setuptools_ext.py", line 217, in cffi_modules
        add_cffi_module(dist, cffi_module)
      File "c:\users\eisem\appdata\local\temp\pip-install-afwht5_8\rpy2\.eggs\cffi-1.12.3-py3.7-win32.egg\cffi\setuptools_ext.py", line 49, in add_cffi_module
        execfile(build_file_name, mod_vars)
      File "c:\users\eisem\appdata\local\temp\pip-install-afwht5_8\rpy2\.eggs\cffi-1.12.3-py3.7-win32.egg\cffi\setuptools_ext.py", line 25, in execfile
        exec(code, glob, glob)
      File "rpy/_rinterface_cffi_build.py", line 546, in <module>
        """ if os.name == 'nt' else ''
      File "c:\users\eisem\appdata\local\temp\pip-install-afwht5_8\rpy2\.eggs\cffi-1.12.3-py3.7-win32.egg\cffi\api.py", line 112, in cdef
        self._cdef(csource, override=override, packed=packed, pack=pack)
      File "c:\users\eisem\appdata\local\temp\pip-install-afwht5_8\rpy2\.eggs\cffi-1.12.3-py3.7-win32.egg\cffi\api.py", line 126, in _cdef
        self._parser.parse(csource, override=override, **options)
      File "c:\users\eisem\appdata\local\temp\pip-install-afwht5_8\rpy2\.eggs\cffi-1.12.3-py3.7-win32.egg\cffi\cparser.py", line 347, in parse
        self._internal_parse(csource)
      File "c:\users\eisem\appdata\local\temp\pip-install-afwht5_8\rpy2\.eggs\cffi-1.12.3-py3.7-win32.egg\cffi\cparser.py", line 352, in _internal_parse
        ast, macros, csource = self._parse(csource)
      File "c:\users\eisem\appdata\local\temp\pip-install-afwht5_8\rpy2\.eggs\cffi-1.12.3-py3.7-win32.egg\cffi\cparser.py", line 296, in _parse
        self.convert_pycparser_error(e, csource)
      File "c:\users\eisem\appdata\local\temp\pip-install-afwht5_8\rpy2\.eggs\cffi-1.12.3-py3.7-win32.egg\cffi\cparser.py", line 325, in convert_pycparser_error
        raise CDefError(msg)
    cffi.CDefError: cannot parse "blah1 ReadConsole;"
    <cdef source string>:23:5: before: blah1
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
----- Fehler beim Installieren von "rpy2==3.0.5" -----

----- "rpy2==3.0.5" wird installiert -----
Collecting rpy2==3.0.5
  Using cached https://files.pythonhosted.org/packages/c7/43/401afad8556bf92b08bd7d422cacac614b0e8dd2bce31848318bbcb18f48/rpy2-3.0.5.tar.gz
    ERROR: Command errored out with exit status 1:
     command: 'C:\Users\eisem\AppData\Local\Programs\Python\Python37-32\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\eisem\\AppData\\Local\\Temp\\pip-install-urxn3u1y\\rpy2\\setup.py'"'"'; __file__='"'"'C:\\Users\\eisem\\AppData\\Local\\Temp\\pip-install-urxn3u1y\\rpy2\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: C:\Users\eisem\AppData\Local\Temp\pip-install-urxn3u1y\rpy2\
    Complete output (69 lines):
    warning: no previously-included files found matching 'setup.pyc'
    warning: no previously-included files matching 'yacctab.*' found under directory 'tests'
    warning: no previously-included files matching 'lextab.*' found under directory 'tests'
    warning: no previously-included files matching 'yacctab.*' found under directory 'examples'
    warning: no previously-included files matching 'lextab.*' found under directory 'examples'
    zip_safe flag not set; analyzing archive contents...
    pycparser.ply.__pycache__.lex.cpython-37: module references __file__
    pycparser.ply.__pycache__.lex.cpython-37: module MAY be using inspect.getsourcefile
    pycparser.ply.__pycache__.yacc.cpython-37: module references __file__
    pycparser.ply.__pycache__.yacc.cpython-37: module MAY be using inspect.getsourcefile
    pycparser.ply.__pycache__.yacc.cpython-37: module MAY be using inspect.stack
    pycparser.ply.__pycache__.ygen.cpython-37: module references __file__

    Installed c:\users\eisem\appdata\local\temp\pip-install-urxn3u1y\rpy2\.eggs\pycparser-2.19-py3.7.egg
    Traceback (most recent call last):
      File "c:\users\eisem\appdata\local\temp\pip-install-urxn3u1y\rpy2\.eggs\cffi-1.12.3-py3.7-win32.egg\cffi\cparser.py", line 294, in _parse
        ast = _get_parser().parse(fullcsource)
      File "c:\users\eisem\appdata\local\temp\pip-install-urxn3u1y\rpy2\.eggs\pycparser-2.19-py3.7.egg\pycparser\c_parser.py", line 152, in parse
        debug=debuglevel)
      File "c:\users\eisem\appdata\local\temp\pip-install-urxn3u1y\rpy2\.eggs\pycparser-2.19-py3.7.egg\pycparser\ply\yacc.py", line 331, in parse
        return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
      File "c:\users\eisem\appdata\local\temp\pip-install-urxn3u1y\rpy2\.eggs\pycparser-2.19-py3.7.egg\pycparser\ply\yacc.py", line 1199, in parseopt_notrack
        tok = call_errorfunc(self.errorfunc, errtoken, self)
      File "c:\users\eisem\appdata\local\temp\pip-install-urxn3u1y\rpy2\.eggs\pycparser-2.19-py3.7.egg\pycparser\ply\yacc.py", line 193, in call_errorfunc
        r = errorfunc(token)
      File "c:\users\eisem\appdata\local\temp\pip-install-urxn3u1y\rpy2\.eggs\pycparser-2.19-py3.7.egg\pycparser\c_parser.py", line 1848, in p_error
        column=self.clex.find_tok_column(p)))
      File "c:\users\eisem\appdata\local\temp\pip-install-urxn3u1y\rpy2\.eggs\pycparser-2.19-py3.7.egg\pycparser\plyparser.py", line 67, in _parse_error
        raise ParseError("%s: %s" % (coord, msg))
    pycparser.plyparser.ParseError: <cdef source string>:23:5: before: blah1

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\eisem\AppData\Local\Temp\pip-install-urxn3u1y\rpy2\setup.py", line 184, in <module>
        'rpy2': ['doc/source/rpy2_logo.png', ]}
      File "C:\Users\eisem\AppData\Local\Programs\Python\Python37-32\lib\site-packages\setuptools\__init__.py", line 145, in setup
        return distutils.core.setup(**attrs)
      File "C:\Users\eisem\AppData\Local\Programs\Python\Python37-32\lib\distutils\core.py", line 108, in setup
        _setup_distribution = dist = klass(attrs)
      File "C:\Users\eisem\AppData\Local\Programs\Python\Python37-32\lib\site-packages\setuptools\dist.py", line 447, in __init__
        k: v for k, v in attrs.items()
      File "C:\Users\eisem\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py", line 292, in __init__
        self.finalize_options()
      File "C:\Users\eisem\AppData\Local\Programs\Python\Python37-32\lib\site-packages\setuptools\dist.py", line 739, in finalize_options
        ep.load()(self, ep.name, value)
      File "c:\users\eisem\appdata\local\temp\pip-install-urxn3u1y\rpy2\.eggs\cffi-1.12.3-py3.7-win32.egg\cffi\setuptools_ext.py", line 217, in cffi_modules
        add_cffi_module(dist, cffi_module)
      File "c:\users\eisem\appdata\local\temp\pip-install-urxn3u1y\rpy2\.eggs\cffi-1.12.3-py3.7-win32.egg\cffi\setuptools_ext.py", line 49, in add_cffi_module
        execfile(build_file_name, mod_vars)
      File "c:\users\eisem\appdata\local\temp\pip-install-urxn3u1y\rpy2\.eggs\cffi-1.12.3-py3.7-win32.egg\cffi\setuptools_ext.py", line 25, in execfile
        exec(code, glob, glob)
      File "rpy/_rinterface_cffi_build.py", line 546, in <module>
        """ if os.name == 'nt' else ''
      File "c:\users\eisem\appdata\local\temp\pip-install-urxn3u1y\rpy2\.eggs\cffi-1.12.3-py3.7-win32.egg\cffi\api.py", line 112, in cdef
        self._cdef(csource, override=override, packed=packed, pack=pack)
      File "c:\users\eisem\appdata\local\temp\pip-install-urxn3u1y\rpy2\.eggs\cffi-1.12.3-py3.7-win32.egg\cffi\api.py", line 126, in _cdef
        self._parser.parse(csource, override=override, **options)
      File "c:\users\eisem\appdata\local\temp\pip-install-urxn3u1y\rpy2\.eggs\cffi-1.12.3-py3.7-win32.egg\cffi\cparser.py", line 347, in parse
        self._internal_parse(csource)
      File "c:\users\eisem\appdata\local\temp\pip-install-urxn3u1y\rpy2\.eggs\cffi-1.12.3-py3.7-win32.egg\cffi\cparser.py", line 352, in _internal_parse
        ast, macros, csource = self._parse(csource)
      File "c:\users\eisem\appdata\local\temp\pip-install-urxn3u1y\rpy2\.eggs\cffi-1.12.3-py3.7-win32.egg\cffi\cparser.py", line 296, in _parse
        self.convert_pycparser_error(e, csource)
      File "c:\users\eisem\appdata\local\temp\pip-install-urxn3u1y\rpy2\.eggs\cffi-1.12.3-py3.7-win32.egg\cffi\cparser.py", line 325, in convert_pycparser_error
        raise CDefError(msg)
    cffi.CDefError: cannot parse "blah1 ReadConsole;"
    <cdef source string>:23:5: before: blah1
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
----- Fehler beim Installieren von "rpy2==3.0.5" -----

This message also appears when installing the whl-file using cmd.

Why does this message appear and how I can install rpy2 without any errors on Windows 10?

Thank you for your help.

Steffen Winkler
  • 2,805
  • 2
  • 35
  • 58
eisem
  • 185
  • 1
  • 10
  • 1
    Hey, googling around a bit, I found two other people with the same issue: One on [superusers](https://superuser.com/questions/1440219/pip-install-rpy2-fails) with no solution and one on a [github project](https://github.com/theislab/anndata2ri/issues/21). From what I can gather there is an issue with some versions of `rpy2`, so maybe try using the 3.1.0 version or 2.9.4 as, according to the github site, those are installable. – Steffen Winkler Aug 14 '19 at 09:14
  • The Installation of rpy2 2.9.4 using Anaconda worked. Thanks. – eisem Aug 14 '19 at 14:22
  • ah, perfect. In that case you are welcome to put that down as a self-answer in a slightly more verbose way. – Steffen Winkler Aug 15 '19 at 07:07

0 Answers0