我已经通过 pip 安装了 rpy2,但遇到了以下问题。
import rpy2.robjects as robjects
返回:
ModuleNotFoundError: No module named '_rinterface_cffi_abi'
我在安装之前确保正确安装了 R,将我的 RHOME(和 R_HOME 只是为了更好的措施)设置为 /usr/lib/R。我在 Python 虚拟环境中。 cffi 版本为 1.16.0。
当我跑步时
python3 -m rpy2.situation
我得到以下信息:
rpy2 version:
3.5.15
Python version:
3.8.10 (default, Nov 22 2023, 10:22:35)
[GCC 9.4.0]
Looking for R's HOME:
Environment variable R_HOME: /usr/lib/R
Calling `R RHOME`: /usr/lib/R
Environment variable R_LIBS_USER: None
R's value for LD_LIBRARY_PATH:
/usr/lib/R/lib:/usr/lib/x86_64-linux-gnu:/usr/lib/jvm/default-java/lib/server
R version:
In the PATH: R version 4.3.2 (2023-10-31) -- "Eye Holes"
Loading R library from rpy2: *** Error while loading: No module named '_rinterface_cffi_api' ***
Additional directories to load R packages from:
None
C extension compilation:
include:
['/usr/share/R/include']
libraries:
['R', 'pcre2-8', 'lzma', 'bz2', 'z', 'rt', 'dl', 'm', 'icuuc', 'icui18n']
library_dirs:
['/usr/lib/R/lib']
extra_compile_args:
['-std=c99']
extra_link_args:
['-Wl,--export-dynamic', '-fopenmp', '-Wl,-Bsymbolic-functions', '-Wl,-z,relro']
Directory for the R shared library:
lib
CFFI extension type
Environment variable: RPY2_CFFI_MODE
Value: CFFI_MODE.API
ABI: ABSENT
API: ABSENT
我期望出现 ABI 或 API CFFI 扩展类型。我怀疑缺少这个
_rinterface_cffi_api
模块会使安装切换到 ABI ode,并且也会失败。
那么为什么 ABI 会失败呢?另外,我是否缺少使用 pip install 通过 API 访问所需的模块?
我最终使用 rpy2/base-ubuntu docker 镜像解决了这个问题。