You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MacBook Air M2环境下ROracle安装失败问题求助

在M2 MacBook Air(macOS Ventura 13.4.1)的brew版R环境中安装ROracle失败

前置条件

  • MacBook Air M2
  • macOS Ventura 13.4.1
  • 通过Homebrew安装的R

系统信息

> Sys.info()                                                                                                
sysname "Darwin" 
release "22.5.0" 
version "Darwin Kernel Version 22.5.0: Thu Jun  8 22:21:34 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T8112"                                                                                                nodename "HostName.local"                                                                                                 machine "arm64"                                                                                                  login "UserName" 
user "UserName" 
effective_user "UserName" 

R环境信息

sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: aarch64-apple-darwin22.4.0 (64-bit)
Running under: macOS Ventura 13.4.1

Matrix products: default
BLAS:   /opt/homebrew/Cellar/openblas/0.3.23/lib/libopenblasp-r0.3.23.dylib 
LAPACK: /opt/homebrew/Cellar/r/4.3.1/lib/R/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] pl_PL.UTF-8/pl_PL.UTF-8/pl_PL.UTF-8/C/pl_PL.UTF-8/pl_PL.UTF-8

time zone: Europe/Warsaw
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.3.1

已完成的准备工作

  • 执行install.packages("DBI")安装DBI依赖
  • 下载并安装Oracle Instant Client 12.2.0.1.0的Basic、SDK和SQL*Plus包(x86架构版本)
  • 配置环境变量:
    ORACLE_HOME="/Users/UserName/instantclient_12_2"
    export ORACLE_HOME
    PATH=$ORACLE_HOME:$PATH
    export PATH
    
  • sqlplus可正常运行

安装操作

执行编译安装命令:

R CMD INSTALL --configure-args='--with-oci-lib=/Users/UserName/instantclient_12_2 --with-oci-inc=/Users/UserName/instantclient_12_2/sdk/include' ~/Downloads/ROracle_1.3-1.1.tar.gz

报错信息

安装过程中出现格式警告,链接阶段提示:

ld: warning: ignoring file /Users/UserName/instantclient_12_2/libclntsh.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64

加载测试时失败:

** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘ROracle’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object  '/opt/homebrew/lib/R/4.3/site-library/00LOCK-ROracle/00new/ROracle/libs/ROracle.so':
  dlopen(/opt/homebrew/lib/R/4.3/site-library/00LOCK-ROracle/00new/ROracle/libs/ROracle.so, 0x0006): symbol not found in flat namespace '_OCIArrayDescriptorAlloc'
Error: loading failed
Execution halted
ERROR: loading failed

解决方案

核心问题是你安装的Oracle Instant Client是x86架构版本,与M2的arm64架构不兼容,导致链接失败。解决步骤如下:

  1. 卸载现有x86版本Instant Client
    删除/Users/UserName/instantclient_12_2目录,同时移除shell配置文件(如~/.zshrc或~/.bashrc)中相关的环境变量配置。

  2. 下载arm64版本的Oracle Instant Client
    选择支持Apple Silicon的版本(建议19.18及以上,Oracle从19.13开始提供arm64版本),下载Basic、SDK、SQL*Plus三个包。

  3. 重新配置环境变量
    解压下载的包到同一目录(如/Users/UserName/instantclient_19_18),在shell配置文件中设置:

    ORACLE_HOME="/Users/UserName/instantclient_19_18"
    export ORACLE_HOME
    PATH=$ORACLE_HOME:$PATH
    export PATH
    export DYLD_LIBRARY_PATH=$ORACLE_HOME:$DYLD_LIBRARY_PATH
    

    执行source ~/.zshrc(或对应shell的配置文件)使配置生效,验证sqlplus可正常运行。

  4. 重新编译安装ROracle
    下载CRAN上的最新稳定版ROracle,执行安装命令:

    R CMD INSTALL --configure-args='--with-oci-lib=$ORACLE_HOME --with-oci-inc=$ORACLE_HOME/sdk/include' ~/Downloads/ROracle_[最新版本号].tar.gz
    
  5. 验证安装
    启动R,执行library(ROracle)测试是否加载成功。

内容的提问来源于stack exchange,提问作者grzeh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 21:30:26