oracle 在 OS X Mavericks 上安装 RODBC/ROracle 包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26210317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 02:33:08  来源:igfitidea点击:

Installation of RODBC/ROracle packages on OS X Mavericks

roraclerodbc

提问by runningbirds

I have been trying to install some packages such as RODBC, ROracle or RGtk2 - used for rattle. I would really appreciate it if someone could help me get around this problem so that I could use these applications on a Mac with mavericks and with 3.1.1 R

我一直在尝试安装一些软件包,例如 RODBC、ROracle 或 RGtk2 - 用于拨浪鼓。如果有人能帮助我解决这个问题,我将不胜感激,这样我就可以在带有 Mavericks 和 3.1.1 R 的 Mac 上使用这些应用程序

I get this sort of error for both RODBC and RGtk2:

对于 RODBC 和 RGtk2,我都遇到了这种错误:

package ‘RGtk2' is available as a source package but not as a binary Warning in install.packages : package ‘RGtk2' is not available (for R version 3.1.1)

包“RGtk2”可用作源包,但不能用作 install.packages 中的二进制警告:包“RGtk2”不可用(对于 R 版本 3.1.1)

When I try to use type='source', I can download or start to download but then I get this sort of error message...

当我尝试使用 type='source' 时,我可以下载或开始下载,但随后我收到此类错误消息...

Warning in install.packages : installation of package ‘RODBC' had non-zero exit status

install.packages 中的警告:安装包“RODBC”的退出状态非零

回答by joran

This answer will cover installing RODBC and ROracle on OS X, specifically on Mavericks and later.

该答案将涵盖在 OS X 上安装 RODBC 和 ROracle,特别是在 Mavericks 及更高版本上。

Both packages now need to be built (compiled) from source. This means that the first thing you need is to download XCode and the associated "command line tools" so that you actually havea compiler. How you do this has changed with basically every version of OS X/XCode, but if you start Googling you will probably end up landing here.

这两个包现在都需要从源代码构建(编译)。这意味着您需要的第一件事是下载 XCode 和相关的“命令行工具”,以便您真正拥有一个编译器。基本上每个版本的 OS X/XCode 都改变了你这样做的方式,但如果你开始谷歌搜索,你可能最终会登陆这里

Once you have that in place...

一旦你有了它......

RODBC

RODBC

Since OS X 10.9 (Mavericks) Apple stopped including the iODBC SQL header files along with the "command line tools" that R users on OS X are accustomed to installing in order to build R packages from source.

从 OS X 10.9 (Mavericks) 开始,Apple 停止包含 iODBC SQL 头文件以及 OS X 上的 R 用户习惯于安装的“命令行工具”,以便从源代码构建 R 包。

So if you try to build RODBC from source on Mavericks at this point you should get an error like:

因此,如果此时您尝试在 Mavericks 上从源代码构建 RODBC,您应该会收到如下错误:

configure: error: "ODBC headers sql.h and sqlext.h not found"

配置:错误:“找不到 ODBC 标头 sql.h 和 sqlext.h”

To fix this, you need to download the latest version of iODBC (www.iodbc.org), and then unzip the file and set your header and library search paths to the location where you put the unzipped package. If you don't know how to set your search paths, you could just put the header files (sql.h and sqlext.h) in the /usr/includedirectory, and the libiodbc.afile in the /usr/libdirectory.

要解决此问题,您需要下载最新版本的 iODBC (www.iodbc.org),然后解压缩文件并将您的标题和库搜索路径设置为放置解压缩包的位置。如果您不知道如何设置搜索路径,您可以将头文件(sql.h 和 sqlext.h)放在/usr/include目录中,并将libiodbc.a文件放在/usr/lib目录中。

Then you should be able to do

那么你应该能够做到

install.packages("RODBC",type = "source")

without any problems. Presumably this would work as well with the other major open source ODBC project, unixODBC, as well, but I have not tried that.

没有任何问题。据推测,这也适用于其他主要的开源 ODBC 项目 unixODBC,但我还没有尝试过。

I have tested this (and the homebrew method in another answer) on El Capitan and both still work.

我已经在 El Capitan 上测试了这个(以及另一个答案中的自制方法),两者都仍然有效。

ROracle

甲骨文

This is more complicated. However, ROracle can be installed on OS X (I have tested this on Mountain Lion through El Capitan). Since ROracle relies on the Oracle Instant Client, there are no binaries available for any platform. There are detailed installation instructions for the package here.

这个比较复杂。但是,ROracle 可以安装在 OS X 上(我已经通过 El Capitan 在 Mountain Lion 上对此进行了测试)。由于 ROracle 依赖于 Oracle Instant Client,因此没有适用于任何平台的二进制文件。此处提供了该软件包的详细安装说明。

For OS X, we need to (mostly) follow the Linux instructions.

对于 OS X,我们需要(主要)遵循 Linux 说明。

First, download the appropriate Oracle Instant Client, as well as the SDK, as directed in the Linuz instructions.

首先,按照 Linuz 说明中的指示下载相应的Oracle Instant Client以及 SDK。

The Linux install instructions mention installing the client from an RPM, which will place everything "in the right place". I wasn't able to figure out whether that even applied for OS X, so I simply unzipped the client in a directory I created and placed the SDK inside that directory in /sdk.

Linux 安装说明提到从 RPM 安装客户端,这会将所有内容“放在正确的位置”。我无法弄清楚这是否适用于 OS X,所以我只是将客户端解压缩到我创建的目录中,并将 SDK 放在/sdk.

The Linux install instructions then direct us to create a symbolic link for libclntsh.so.11.1. Since this is OS X, it's actually called libclntsh.dylib.11.1. So we need to cd to the directory where we unzipped the client and then run

Linux 安装说明然后指导我们为 libclntsh.so.11.1 创建符号链接。由于这是 OS X,它实际上被称为 libclntsh.dylib.11.1。所以我们需要cd到我们解压客户端的目录然后运行

ln -s libclntsh.dylib.11.1 libclntsh.dylib

On OS X, we then set the DYLD_LIBRARY_PATH, not the LD_LIBRARY_PATH:

在 OS X 上,我们然后设置DYLD_LIBRARY_PATH,而不是LD_LIBRARY_PATH

export DYLD_LIBRARY_PATH=/scratch/instantclient_11_2:$DYLD_LIBRARY_PATH

using whatever path is correct for your machine.

使用适合您机器的任何路径。

I was never able to get ROracle to compile with an OCI_LIBenvironment variable. Instead, I used the --with-oci-libcompiler flag option:

我永远无法让 ROracle 使用OCI_LIB环境变量进行编译。相反,我使用了--with-oci-lib编译器标志选项:

R CMD INSTALL --configure-args='--with-oci-lib=/scratch/instantclient_11_2' ROracle_1.1-11.tar.gz

again using whatever path and ROracle version number is appropriate.

再次使用任何合适的路径和 ROracle 版本号。

If you are connecting to an Oracle database using a tnsnames.ora file, you'll also need to set a TNS_ADMIN environment variable to point to the location of that file.

如果您使用 tnsnames.ora 文件连接到 Oracle 数据库,您还需要设置 TNS_ADMIN 环境变量以指向该文件的位置。

One last gotcha: you may find (as I did) that this will all work only if you launch R from the command line (i.e. Terminal). Specifically, if you launch either RGui.app or RStudio.app from the GUI, and then try to run library(ROracle)you will get an error saying something to the effect of

最后一个问题:您可能会发现(正如我所做的那样)只有当您从命令行(即终端)启动 R 时,这一切才会起作用。具体来说,如果您从 GUI 启动 RGui.app 或 RStudio.app,然后尝试运行,library(ROracle)您将收到一条错误消息,说明

> library("ROracle")
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/ROracle/libs/ROracle.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/ROracle/libs/ROracle.so, 6): Library not loaded: /ade/b/3071542110/oracle/rdbms/lib/libclntsh.dylib.11.1
  Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/ROracle/libs/ROracle.so
  Reason: image not found
Error: package or namespace load failed for ‘ROracle'

This will happen even though Sys.getenv("DYLD_LIBRARY_PATH")faithfully reports the correct path.

即使Sys.getenv("DYLD_LIBRARY_PATH")忠实地报告了正确的路径,也会发生这种情况。

For a while, I hacked together a "solution" where I created a shell script that launched RStudio/RGui upon startup, and just had to remember to always subsequently launch them via

有一段时间,我编写了一个“解决方案”,我在其中创建了一个 shell 脚本,该脚本在启动时启动 RStudio/RGui,并且只需要记住始终通过以下方式启动它们

open -a R.app
open -a RStudio.app

The problem apparently has to do with how environment variables are made available to GUI launched applications in OS X. As is usually the case, I eventually found the solution on StackOverflow. Editing the /etc/launchd.conffile solved this problem, so ROracle now loads even when RStudio/RGui are launched from the Finder. Though note herethat the /etc/launchd.confsolution is no longer supported in Yosemite. That answer suggests you now need to set up a start-up plist file just to set the environment for launchctlon startup.

问题显然与 OS X 中 GUI 启动的应用程序如何使用环境变量有关。通常情况下,我最终在StackOverflow上找到了解决方案。编辑 /etc/launchd.conf文件解决了这个问题,因此即使从 Finder 启动 RStudio/RGui,ROracle 现在也会加载。但要注意这里的是,/etc/launchd.conf在优胜美地解不再支持。该答案表明您现在需要设置一个启动 plist 文件来设置launchctl启动时的环境。

El Capitan Update for ROracle

ROracle 的 El Capitan 更新

I've now gone through the crucible on this one in El Capitan and it works as described above, but only if you disable System Integrity Protectionfirst! Doing that is fairly quick, and instructions are easily found via Google.

我现在已经在 El Capitan 中完成了这个坩埚,它的工作原理如上所述,但前提是您首先禁用系统完整性保护!这样做相当快,并且可以通过 Google 轻松找到说明。

Phew.

呼。

回答by kaboom

If you got homebrew,it would be easy. In terminal,use

如果你有自制软件,那就很容易了。在终端中,使用

brew install unixodbc

In r console,use

在 r 控制台中,使用

install.packages("RODBC",type="source")

Hope it will help

希望它会有所帮助

回答by roffe

If you're using MacPorts, do this:

如果您使用的是 MacPorts,请执行以下操作:

sudo port install unixODBC

Then, create (or, if it exists, edit) a file in your home directory

然后,在您的主目录中创建(或者,如果存在,则编辑)一个文件

~/.R/Makevars

which should contain a line

其中应该包含一行

CFLAGS += -I/opt/local/include

Then, you can install RODBC by

然后,您可以通过以下方式安装 RODBC

install.packages("RODBC",type="source")

Basically, the above

基本上,以上

  • Installs the necessary libraries and header files
  • Tells R where to find them
  • Installs RODBC.
  • 安装必要的库和头文件
  • 告诉 R 在哪里可以找到它们
  • 安装 RODBC。

回答by Roman Lu?trik

You will have to build the package from source by hand. If you go to the RODBCsite, you'll notice that the binaries are not available for Mavericks. Download the package and follow the instruction for building a package from source. These are Windows instructionsbut the general idea is the same. You will need all the necessary OS packages which are being used during the build process of a particular package.

您必须手动从源代码构建包。如果您访问RODBC站点,您会注意到这些二进制文件不可用于 Mavericks。下载包并按照从源代码构建包的说明进行操作。这些是 Windows 说明,但总体思路是相同的。您将需要在特定包的构建过程中使用的所有必要的操作系统包。