简体   繁体   English

pycharm上的rpy2生成分段错误错误

[英]rpy2 on pycharm generates segmentation fault error

I am using (osx) pycharm as ide and anaconda as python (2.7.10) distribution. 我正在使用(osx)pycharm作为ide和anaconda作为python(2.7.10)发行版。 Recently I have installed rpy2 which works quite well on notebook eg 最近我安装了rpy2,它在笔记本电脑上工作得很好

In [5]:import rpy2.robjects as robjects
In [7]:robjects.r.pi[0]
Out[7]:3.141592653589793

But on pycharm I get a segmentation fault error. 但是在pycharm上,我得到了分段错误错误。

import rpy2.robjects as robjects
/Users/xxx/anaconda/envs/analytics3/bin/python.app: line 3: 695 Segmentation fault: 11 /Users/xxx/anaconda/envs/analytics3/python.app/Contents/MacOS/python "$@"

PYcharm support claims that this is a bug in the code. PYcharm支持声称这是代码中的错误。

any ideas what that might be? 任何想法可能是什么?

many thanks 非常感谢

Reinstalling rpy2 from 从重新安装rpy2

conda install -c conda.anaconda.org/rpy2

solved the issue. 解决了这个问题。

If you install rpy2 via conda, and also have a system installation of R on the same machine (eg with RStudio), the system's R installation will be used. 如果您通过conda安装rpy2,并且在同一台计算机上(例如,与RStudio一起)具有R的系统安装,则将使用系统的R安装。 Since this R version doesn't match the one that rpy2 needs, segmentation faults occur. 由于此R版本与rpy2所需的版本不匹配,因此会发生分段错误。

1) remove any existing system installations of R ( see here ). 1)删除R的任何现有系统安装( 请参阅此处 )。 Verify that you don't have any installations of R: 确认您没有任何R的安装:

$>which R
R not found

2) define R_HOME env variable, either in your .rc file: 2)在.rc文件中定义R_HOME env变量:

export R_HOME=/Users/<your user>/anaconda3/envs/<env name>/lib/R

or dynamically in the python project: 或动态地在python项目中:

import os
os.environ['R_HOME'] = '/Users/<your user>/anaconda3/envs/<env name>/lib/R'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM