当前位置:   article > 正文

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

import rpy2 cffi mode is cffi_mode.any

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

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

报如下错误:

  1. ERROR: Complete output from command python setup.py egg_info:
  2. ERROR: Traceback (most recent call last):
  3. File "d:\python_virtualenv\pandas0192\lib\site-packages\cffi\cparser.py", line 276, in _parse
  4. ast = _get_parser().parse(fullcsource)
  5. File "d:\python_virtualenv\pandas0192\lib\site-packages\pycparser\c_parser.py", line 152, in parse
  6. debug=debuglevel)
  7. File "d:\python_virtualenv\pandas0192\lib\site-packages\pycparser\ply\yacc.py", line 331, in parse
  8. return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  9. File "d:\python_virtualenv\pandas0192\lib\site-packages\pycparser\ply\yacc.py", line 1199, in parseopt_notrack
  10. tok = call_errorfunc(self.errorfunc, errtoken, self)
  11. File "d:\python_virtualenv\pandas0192\lib\site-packages\pycparser\ply\yacc.py", line 193, in call_errorfunc
  12. r = errorfunc(token)
  13. File "d:\python_virtualenv\pandas0192\lib\site-packages\pycparser\c_parser.py", line 1761, in p_error
  14. column=self.clex.find_tok_column(p)))
  15. File "d:\python_virtualenv\pandas0192\lib\site-packages\pycparser\plyparser.py", line 66, in _parse_error
  16. raise ParseError("%s: %s" % (coord, msg))
  17. pycparser.plyparser.ParseError: <cdef source string>:23:5: before: blah1
  18. During handling of the above exception, another exception occurred:
  19. Traceback (most recent call last):
  20. File "<string>", line 1, in <module>
  21. File "C:\Users\ADMINI~1\AppData\Local\Temp\pip-install-n564fvky\rpy2\setup.py", line 184, in <module>
  22. 'rpy2': ['doc/source/rpy2_logo.png', ]}
  23. File "d:\python_virtualenv\pandas0192\lib\site-packages\setuptools\__init__.py", line 131, in setup
  24. return distutils.core.setup(**attrs)
  25. File "d:\program files\python361\Lib\distutils\core.py", line 108, in setup
  26. _setup_distribution = dist = klass(attrs)
  27. File "d:\python_virtualenv\pandas0192\lib\site-packages\setuptools\dist.py", line 370, in __init__
  28. k: v for k, v in attrs.items()
  29. File "d:\program files\python361\Lib\distutils\dist.py", line 281, in __init__
  30. self.finalize_options()
  31. File "d:\python_virtualenv\pandas0192\lib\site-packages\setuptools\dist.py", line 529, in finalize_options
  32. ep.load()(self, ep.name, value)
  33. File "d:\python_virtualenv\pandas0192\lib\site-packages\cffi\setuptools_ext.py", line 204, in cffi_modules
  34. add_cffi_module(dist, cffi_module)
  35. File "d:\python_virtualenv\pandas0192\lib\site-packages\cffi\setuptools_ext.py", line 49, in add_cffi_module
  36. execfile(build_file_name, mod_vars)
  37. File "d:\python_virtualenv\pandas0192\lib\site-packages\cffi\setuptools_ext.py", line 25, in execfile
  38. exec(code, glob, glob)
  39. File "rpy/_rinterface_cffi_build.py", line 546, in <module>
  40. """ if os.name == 'nt' else ''
  41. File "d:\python_virtualenv\pandas0192\lib\site-packages\cffi\api.py", line 107, in cdef
  42. self._cdef(csource, override=override, packed=packed)
  43. File "d:\python_virtualenv\pandas0192\lib\site-packages\cffi\api.py", line 121, in _cdef
  44. self._parser.parse(csource, override=override, **options)
  45. File "d:\python_virtualenv\pandas0192\lib\site-packages\cffi\cparser.py", line 315, in parse
  46. self._internal_parse(csource)
  47. File "d:\python_virtualenv\pandas0192\lib\site-packages\cffi\cparser.py", line 320, in _internal_parse
  48. ast, macros, csource = self._parse(csource)
  49. File "d:\python_virtualenv\pandas0192\lib\site-packages\cffi\cparser.py", line 278, in _parse
  50. self.convert_pycparser_error(e, csource)
  51. File "d:\python_virtualenv\pandas0192\lib\site-packages\cffi\cparser.py", line 307, in convert_pycparser_error
  52. raise CDefError(msg)
  53. cffi.error.CDefError: cannot parse "blah1 ReadConsole;"
  54. <cdef source string>:23:5: before: blah1
  55. ----------------------------------------
  56. 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

源码上是这样写的:

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

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

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

  1. >>> import rpy2
  2. >>> from rpy2.robjects.packages import importr
  3. Traceback (most recent call last):
  4. File "<stdin>", line 1, in <module>
  5. File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  6. File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  7. File "<frozen importlib._bootstrap>", line 646, in _load_unlocked
  8. File "<frozen importlib._bootstrap>", line 616, in _load_backward_compatible
  9. 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>
  10. File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  11. File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  12. File "<frozen importlib._bootstrap>", line 646, in _load_unlocked
  13. File "<frozen importlib._bootstrap>", line 616, in _load_backward_compatible
  14. File "D:\python_virtualenv\nlp_learn\lib\site-packages\rpy2-3.1.0.dev0-py3.6.egg\rpy2\rinterface.py", line 5, in <module>
  15. File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  16. File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  17. File "<frozen importlib._bootstrap>", line 646, in _load_unlocked
  18. File "<frozen importlib._bootstrap>", line 616, in _load_backward_compatible
  19. 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>
  20. 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
  21. 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
  22. ValueError: The system "%s" is not supported.

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

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

  1. 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
  2. 文档地址: 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 + 轮子名称即可。

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

 

转载于:https://www.cnblogs.com/hufulinblog/p/11215126.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/534834
推荐阅读
相关标签
  

闽ICP备14008679号