在mavericks中安装RMySQL



我在安装RMySQL时遇到麻烦。我试图从它的源代码安装它在以下方式:

install.packages("/path/to/package/RMySQL_0.9-3.tar.gz",repos = NULL,type="source")

得到:

Installing package into ‘/Users/Library/R/3.1/library’
(as ‘lib’ is unspecified)
* installing *source* package ‘RMySQL’ ...
** package ‘RMySQL’ successfully unpacked and MD5 sums checked
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking how to run the C preprocessor... gcc -E
checking for compress in -lz... yes
checking for getopt_long in -lc... yes
checking for mysql_init in -lmysqlclient... no
checking for egrep... grep -E
checking for ANSI C header files... 
rm: conftest.dSYM: is a directory
rm: conftest.dSYM: is a directory
yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking mysql.h usability... no
checking mysql.h presence... no
checking for mysql.h... no
checking for mysql_init in -lmysqlclient... no
checking for mysql_init in -lmysqlclient... no
checking for mysql_init in -lmysqlclient... no
checking for mysql_init in -lmysqlclient... no
checking for mysql_init in -lmysqlclient... no
checking for mysql_init in -lmysqlclient... no
checking for mysql_init in -lmysqlclient... no
checking /usr/local/include/mysql/mysql.h usability... no
checking /usr/local/include/mysql/mysql.h presence... no
checking for /usr/local/include/mysql/mysql.h... no
checking /usr/include/mysql/mysql.h usability... no
checking /usr/include/mysql/mysql.h presence... no
checking for /usr/include/mysql/mysql.h... no
checking /usr/local/mysql/include/mysql/mysql.h usability... no
checking /usr/local/mysql/include/mysql/mysql.h presence... no
checking for /usr/local/mysql/include/mysql/mysql.h... no
checking /opt/include/mysql/mysql.h usability... no
checking /opt/include/mysql/mysql.h presence... no
checking for /opt/include/mysql/mysql.h... no
checking /include/mysql/mysql.h usability... no
checking /include/mysql/mysql.h presence... no
checking for /include/mysql/mysql.h... no
Configuration error:
  could not find the MySQL installation include and/or library
  directories.  Manually specify the location of the MySQL
  libraries and the header files and re-run R CMD INSTALL.
INSTRUCTIONS:
1. Define and export the 2 shell variables PKG_CPPFLAGS and
   PKG_LIBS to include the directory for header files (*.h)
   and libraries, for example (using Bourne shell syntax):
      export PKG_CPPFLAGS="-I<MySQL-include-dir>"
      export PKG_LIBS="-L<MySQL-lib-dir> -lmysqlclient"
   Re-run the R INSTALL command:
      R CMD INSTALL RMySQL_<version>.tar.gz
2. Alternatively, you may pass the configure arguments
      --with-mysql-dir=<base-dir> (distribution directory)
   or
      --with-mysql-inc=<base-inc> (where MySQL header files reside)
      --with-mysql-lib=<base-lib> (where MySQL libraries reside)
   in the call to R INSTALL --configure-args='...' 
   R CMD INSTALL --configure-args='--with-mysql-dir=DIR' RMySQL_<version>.tar.gz
ERROR: configuration failed for package ‘RMySQL’
* removing ‘/Library/R/3.1/library/RMySQL’
Warning in install.packages :
  installation of package ‘/path/to/package/RMySQL_0.9-3.tar.gz’ had non-zero exit status

我可能会大喊大叫,因为我得到指示,但术语是我的头,我已经尝试了过去的两个小时。有人能帮忙吗?

我已经成功地从源代码安装了RMySQL 0.9-3:

    OS X Mavericks 10.9.4 r3.1.0和RStudio 0.98.945从CRAN和rstudio.com安装Xcode 5.1.1和相应的命令行工具

有其他方法可以实现相同的目标,但我会尽量提供最友好的方法。以下是主要步骤:

1。确保"gcc"可用。(看起来像)

进入"应用程序>实用程序",打开终端,输入以下命令验证命令行工具是否存在:($为终端中的命令提示符)

$ gcc
clang: error: no input files

如果您收到-bash: gcc: command not found,您将需要以独立或Xcode方式安装命令行工具(gcc)。

2。

Homebrew是一个包管理系统,它简化了Mac OS X操作系统上的软件安装。

首先,从终端安装自制软件:

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

之后,输入"brew"命令检查是否安装了Homebrew。然后安装MySQL:

$ brew install mysql

你应该看到下载,浇注,警告,最后Summary显示MySQL已经安装。

您可以通过以root身份连接到本地MySQL服务器来验证安装是否成功,并使用(默认)空密码:

$ mysql
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.6.19 Homebrew
... (skipped) ...
mysql> 

使用"exit"退出MySQL shell。您可能在启动或连接本地MySQL服务器时遇到问题,但这超出了范围。

3。

到目前为止,所有步骤都是在Terminal中完成的。虽然这一步也可以在Terminal中完成,但我将展示如何在RStudio中完成。从您的错误消息:
Configuration error:
  could not find the MySQL installation include and/or library
  directories.  Manually specify the location of the MySQL
  libraries and the header files and re-run R CMD INSTALL.
INSTRUCTIONS:
1. Define and export the 2 shell variables PKG_CPPFLAGS and
   PKG_LIBS to include the directory for header files (*.h)
   and libraries, for example (using Bourne shell syntax):
      export PKG_CPPFLAGS="-I<MySQL-include-dir>"
      export PKG_LIBS="-L<MySQL-lib-dir> -lmysqlclient"
   Re-run the R INSTALL command:
      R CMD INSTALL RMySQL_<version>.tar.gz

这意味着R找不到要包含的头文件(include things)和要链接的库(lib things)。

该指令告诉您设置两个环境变量PKG_CPPFLAGSPKG_LIBS,以指示includelib的位置。

假设你在Homebrew中使用默认路径安装了MySQL。在RStudio中,您可以通过以下方式设置它们:(>是RStudio中的命令提示符)

### These are the KEY COMMANDS in this turotial ###
> Sys.setenv(PKG_CPPFLAGS = "-I/usr/local/include/mysql")
> Sys.setenv(PKG_LIBS = "-L/usr/local/lib -lmysqlclient")

最后,你应该能够正确地从源代码安装RMySQL !从CRAN repo或本地文件。

> install.packages("RMySQL", type = "source")

> install.packages("/path/to/package/RMySQL_0.9-3.tar.gz", repos = NULL, type = "source")

都将给您成功消息:

** libs
clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include/mysql/ -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include    -fPIC  -Wall -mtune=core2 -g -O2  -c RS-DBI.c -o RS-DBI.o
clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include/mysql/ -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include    -fPIC  -Wall -mtune=core2 -g -O2  -c RS-MySQL.c -o RS-MySQL.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -o RMySQL.so RS-DBI.o RS-MySQL.o -L/usr/local/lib/ -lmysqlclient -lz -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
installing to /Library/Frameworks/R.framework/Versions/3.1/Resources/library/RMySQL/libs
** R
** inst
** preparing package for lazy loading
Creating a generic function for ‘format’ from package ‘base’ in package ‘RMySQL’
Creating a generic function for ‘print’ from package ‘base’ in package ‘RMySQL’
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (RMySQL)

像往常一样,加载RMySQL包:

> library(RMySQL)
Loading required package: DBI
> 

注: R中的install.packages()实际上在Terminal (Unix shell)环境下运行R CMD INSTALL xxx。因此,如果您喜欢终端方式,您也可以在终端中通过export命令设置PKG_CPPFLAGSPKG_LIBS,并运行R CMD INSTALL RMySQL_xxx.tar.gz从手动下载的源包中安装。

所以下面的方法也可以在Terminal中用于步骤3:

$ export PKG_CPPFLAGS="-I/usr/local/include/mysql"
$ export PKG_LIBS="-L/usr/local/lib -lmysqlclient"
$ R CMD INSTALL RMySQL_0.9-3.tar.gz

我按照上面的指示做了:

brew install mysql

然后在RStudio:

Sys.setenv(PKG_CPPFLAGS = "-I/usr/local/include/mysql")
Sys.setenv(PKG_LIBS = "-L/usr/local/lib -lmysqlclient")
install.packages("RMySQL", type="source")

给出错误:

In file included from RS-MySQL.c:22: 
./RS-MySQL.h:32:10: fatal error: 'mysql.h' file not found
#include <mysql.h>
         ^ 1 error generated. 
make: *** [RS-MySQL.o] Error 1 
ERROR: compilation failed for package ‘RMySQL’
* removing ‘/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RMySQL’
要解决这个问题,请将RStudio中的最后一个命令更改为:
install.packages("RMySQL", 
    configure.args="--with-mysql-dir=/usr/local/bin/  
    --with-mysql-inc=/usr/local/include/mysql  
    --with-mysql-lib=/usr/local/lib", type="source")

我在使用Ubuntu 13.10时遇到了同样的问题。无法使用RStudio包管理器安装RMySQL。确保安装libmysqld-dev包并在配置参数

中给出正确的路径
sudo apt-get install libmysqld-dev

之后,根据您的机器上的mysql安装修改以下参数

R CMD INSTALL   --configure-args='--with-mysql-dir=/usr/lib/mysql'  ~/Downloads/RMySQL_0.9-3.tar.gz

你会在这里找到完整的解决方案。您可能需要根据您的系统环境进行配置。它在我的

  • Maverik OS X 10.9.4
  • R 3.1.1
  • mysql-5.6.20-osx10.8-x86_64

对于我来说,上面设置PKG_CPPFLAGS和PKG_LIBS的解决方案不再适用于RMySQL 0.10.3(但适用于0.9-3)。我的解决方案是将系统环境变量MYSQL_DIR(不是MYSQL_HOME)设置为MySQL客户端目录,其中包括'include'和'lib'。还要确保libmysqlclient库在运行时可用(例如复制到R的lib文件夹)。

最新更新