If you install rpy2 via conda, and also have a system installation of R on the same machine (e.g with RStudio), the system's R installation will be used. Since this R version doesn't match the one that rpy2 needs, segmentation faults occur.
1) remove any existing system installations of R (see here). Verify that you don't have any installations of R:
$>which R
R not found
2) define R_HOME
env variable, either in your .rc file:
export R_HOME=/Users/<your user>/anaconda3/envs/<env name>/lib/R
or dynamically in the python project:
import os
os.environ['R_HOME'] = '/Users/<your user>/anaconda3/envs/<env name>/lib/R'
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…