在OS X Mavericks上安装RODBC/ROracle软件包 [英] Installation of RODBC/ROracle packages on OS X Mavericks

查看:83
本文介绍了在OS X Mavericks上安装RODBC/ROracle软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试安装一些软件包,例如RODBC,ROracle或RGtk2-用于发出嘎嘎声.如果有人可以帮助我解决此问题,以便我可以在带有标枪和3.1.1 R的Mac上使用这些应用程序,我将不胜感激.

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

软件包"RGtk2"可以作为源软件包使用,而不能作为二进制文件使用 install.packages中的警告:软件包"RGtk2"不可用(适用于 R版本3.1.1)

当我尝试使用type ='source'时,我可以下载或开始下载,但是随后出现这种错误消息...

在install.packages中的警告: 软件包"RODBC"的安装退出状态为非零

解决方案

此答案将涵盖在OS X上(特别是在Mavericks及更高版本上)安装RODBC和ROracle.

这两个软件包现在都需要从源代码构建(编译).这意味着您首先需要下载XCode和相关的命令行工具",以便实际上拥有编译器.基本上每个版本的OS X/XCode的操作方式都已改变,但是如果您开始使用Google搜索,您可能最终会在此处登陆 a>.

一旦您准备好了……

RODBC

自OS X 10.9(小牛)以来,苹果公司就停止了将iODBC SQL头文件以及 OS X上的R用户习惯于安装以构建R的命令行工具" 来自源的软件包.

因此,如果您此时尝试从Mavericks上的源代码构建RODBC,则会出现类似以下错误:

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

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

那你应该就能做到

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

没有任何问题.大概这也可以与其他主要的开源ODBC项目unixODBC一起使用,但是我还没有尝试过.

我已经在El Capitan上对此进行了测试(以及另一种答案中的自制方法),并且两者仍然可以正常工作.

ROracle

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

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

首先,下载相应的 Oracle Instant Client 以及SDK,如Linuz说明中所述.

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

然后,Linux安装说明指导我们为libclntsh.so.11.1创建一个符号链接.自从 这是OS X,实际上叫做libclntsh.dylib.11.1.所以我们需要cd到目录 我们解压缩客户端,然后运行

ln -s libclntsh.dylib.11.1 libclntsh.dylib

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

export DYLD_LIBRARY_PATH=/scratch/instantclient_11_2:$DYLD_LIBRARY_PATH

使用适合您计算机的任何路径.

我始终无法让ROracle使用OCI_LIB环境变量进行编译.反而, 我使用了--with-oci-lib编译器标志选项:

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

再次使用适当的路径和ROracle版本号.

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

最后一个陷阱:您可能会发现(就像我一样),只有启动R才能正常工作 从命令行(即终端).具体来说,如果您启动RGui.app或 从GUI,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’

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

有一阵子,我破解了一个解决方案",在其中创建了一个外壳脚本,该外壳脚本启动了 RStudio/RGui在启动时,只需要记住始终随后通过以下方式启动它们即可:

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

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

用于ROracle的El Capitan更新

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

Ph.

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

I get this sort of error for both RODBC and 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)

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

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

解决方案

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

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 have a 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.

Once you have that in place...

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.

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

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

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/include directory, and the libiodbc.a file in the /usr/lib directory.

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.

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

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.

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

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

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.

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

ln -s libclntsh.dylib.11.1 libclntsh.dylib

On OS X, we then set the DYLD_LIBRARY_PATH, not the 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_LIB environment variable. Instead, I used the --with-oci-lib compiler flag option:

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.

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.

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

> 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.

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

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.conf file solved this problem, so ROracle now loads even when RStudio/RGui are launched from the Finder. Though note here that the /etc/launchd.conf solution 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 launchctl on startup.

El Capitan Update for ROracle

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 Protection first! Doing that is fairly quick, and instructions are easily found via Google.

Phew.

这篇关于在OS X Mavericks上安装RODBC/ROracle软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆