安装rpy2 报错<cdef source string>:23:5: before: blah1 解决办法就是直接下载一个rpy2的轮子

win7上安装rpy2, python环境是3.6.1。

使用pip install rpy2直接安装rpy2,对应的版本时rpy2 3.0.5

报如下错误:

ERROR: Complete output from command python setup.py egg_info:
ERROR: Traceback (most recent call last):
File "d:\python_virtualenv\pandas0192\lib\site-packages\cffi\cparser.py", line 276, in _parse
ast = _get_parser().parse(fullcsource)
File "d:\python_virtualenv\pandas0192\lib\site-packages\pycparser\c_parser.py", line 152, in parse
debug=debuglevel)
File "d:\python_virtualenv\pandas0192\lib\site-packages\pycparser\ply\yacc.py", line 331, in parse
return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
File "d:\python_virtualenv\pandas0192\lib\site-packages\pycparser\ply\yacc.py", line 1199, in parseopt_notrack
tok = call_errorfunc(self.errorfunc, errtoken, self)
File "d:\python_virtualenv\pandas0192\lib\site-packages\pycparser\ply\yacc.py", line 193, in call_errorfunc
r = errorfunc(token)
File "d:\python_virtualenv\pandas0192\lib\site-packages\pycparser\c_parser.py", line 1761, in p_error
column=self.clex.find_tok_column(p)))
File "d:\python_virtualenv\pandas0192\lib\site-packages\pycparser\plyparser.py", line 66, 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\ADMINI~1\AppData\Local\Temp\pip-install-n564fvky\rpy2\setup.py", line 184, in <module>
'rpy2': ['doc/source/rpy2_logo.png', ]}
File "d:\python_virtualenv\pandas0192\lib\site-packages\setuptools\__init__.py", line 131, in setup
return distutils.core.setup(**attrs)
File "d:\program files\python361\Lib\distutils\core.py", line 108, in setup
_setup_distribution = dist = klass(attrs)
File "d:\python_virtualenv\pandas0192\lib\site-packages\setuptools\dist.py", line 370, in __init__
k: v for k, v in attrs.items()
File "d:\program files\python361\Lib\distutils\dist.py", line 281, in __init__
self.finalize_options()
File "d:\python_virtualenv\pandas0192\lib\site-packages\setuptools\dist.py", line 529, in finalize_options
ep.load()(self, ep.name, value)
File "d:\python_virtualenv\pandas0192\lib\site-packages\cffi\setuptools_ext.py", line 204, in cffi_modules
add_cffi_module(dist, cffi_module)
File "d:\python_virtualenv\pandas0192\lib\site-packages\cffi\setuptools_ext.py", line 49, in add_cffi_module
execfile(build_file_name, mod_vars)
File "d:\python_virtualenv\pandas0192\lib\site-packages\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 "d:\python_virtualenv\pandas0192\lib\site-packages\cffi\api.py", line 107, in cdef
self._cdef(csource, override=override, packed=packed)
File "d:\python_virtualenv\pandas0192\lib\site-packages\cffi\api.py", line 121, in _cdef
self._parser.parse(csource, override=override, **options)
File "d:\python_virtualenv\pandas0192\lib\site-packages\cffi\cparser.py", line 315, in parse
self._internal_parse(csource)
File "d:\python_virtualenv\pandas0192\lib\site-packages\cffi\cparser.py", line 320, in _internal_parse
ast, macros, csource = self._parse(csource)
File "d:\python_virtualenv\pandas0192\lib\site-packages\cffi\cparser.py", line 278, in _parse
self.convert_pycparser_error(e, csource)
File "d:\python_virtualenv\pandas0192\lib\site-packages\cffi\cparser.py", line 307, in convert_pycparser_error
raise CDefError(msg)
cffi.error.CDefError: cannot parse "blah1 ReadConsole;"
<cdef source string>:23:5: before: blah1
----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in C:\Users\ADMINI~1\AppData\Local\Temp\pip-install-n564fvky\rpy2\

报错的大概意思是blah1 ReadConsole;这句话无法执行, 查看文件_rinterface_cffi_build.py,发现blah1这个类的定义在_rinterface_cffi_build.py文件中并没有。

在rpy2的最新的开源代码中,_rinterface_cffi_build.py文件中是有关于 "blah1"这个的定义的。源码网站地址: https://bitbucket.org/rpy2/rpy2/src/default/rpy/_rinterface_cffi_build.py

源码上是这样写的:

if os.name == 'nt':
    ffibuilder.cdef("""
    typedef int (*blah1) (const char *, char *, int, int);
    typedef void (*blah2) (const char *, int);
    typedef void (*blah3) (void);
    typedef void (*blah4) (const char *);
    /* Return value here is expected to be 1 for Yes, -1 for No and 
     * 0 for Cancel: symbolic constants in graphapp.h */
    typedef int (*blah5) (const char *);
    typedef void (*blah6) (int);
    typedef void (*blah7) (const char *, int, int);
    typedef enum {RGui, RTerm, LinkDLL} UImode;

    """)

然后我试了把开源代码直接下载下来,然后使用python setup.py install方式安装,rpy2这回可以正常安装上了。

然后检查一下可不可以使用:

>>> import rpy2
>>> from rpy2.robjects.packages import importr
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 646, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 616, in _load_backward_compatible
  File "D:\python_virtualenv\nlp_learn\lib\site-packages\rpy2-3.1.0.dev0-py3.6.egg\rpy2\robjects\__init__.py", line 14, in <module>
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 646, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 616, in _load_backward_compatible
  File "D:\python_virtualenv\nlp_learn\lib\site-packages\rpy2-3.1.0.dev0-py3.6.egg\rpy2\rinterface.py", line 5, in <module>
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 646, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 616, in _load_backward_compatible
  File "D:\python_virtualenv\nlp_learn\lib\site-packages\rpy2-3.1.0.dev0-py3.6.egg\rpy2\rinterface_lib\openrlib.py", line 21, in <module>
  File "D:\python_virtualenv\nlp_learn\lib\site-packages\rpy2-3.1.0.dev0-py3.6.egg\rpy2\rinterface_lib\openrlib.py", line 16, in _dlopen_rlib
  File "D:\python_virtualenv\nlp_learn\lib\site-packages\rpy2-3.1.0.dev0-py3.6.egg\rpy2\situation.py", line 71, in get_rlib_path
ValueError: The system "%s" is not supported.

 得,(¬_¬),这意思是不支持当前的系统。 

 找了一个rpy2的文档,文档上是这么说的: 

Microsoft’s Windows - unofficial and unsupported binaries are provided by Christoph Gohlke (http://www.lfd.uci.edu/~gohlke/pythonlibs/); there is otherwise currently close to no support for this platform
文档地址: https://rpy2.github.io/doc/latest/html/overview.html#installation

 就是说rpy2不支持windows这个平台,如果想要使用,请到https://www.lfd.uci.edu/~gohlke/pythonlibs/网站上去下载一个编译好的轮子。

   这个网站上rpy2的最新版本是2.9.5, 选择好要下载的版本,选择好对应的系统, 下载完成后直接使用pip install + 轮子名称即可。

  问题解决,早知道我直接去下个轮子就好了,还看了半天源码,浪费时间!!!

 

posted @ 2019-07-19 18:32  桑胡  阅读(1432)  评论(1编辑  收藏  举报