【问题标题】:Installing RMySQL in mavericks在 Mavericks 中安装 RMySQL
【发布时间】:2014-07-02 17:19:26
【问题描述】:

我在安装 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

因为我得到指示,我可能会为此大喊大叫,但术语在我头上,我在过去的两个小时里一直在尝试。有人可以帮忙吗?

【问题讨论】:

  • 您能否更具体地说明您不理解的第一条指令是什么? (报错是告诉你找不到mysql头文件,第一条指令是告诉你如何告诉它头文件在哪里。)
  • 从哪里获得这些头文件?
  • 嗯,大概你已经安装了 MySQL。如果你还没有,那么你真的不能指望 RMySQL 工作,现在可以吗?头文件(不是标题)是该安装的一部分。它们将位于您安装 MySQL 的任何位置。
  • 你可以通过homebrew安装mysql。

标签: r osx-mavericks


【解决方案1】:

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

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

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

1.确保您有可用的“gcc”。(看起来像)

转到应用程序>实用程序,打开终端,然后键入以下命令以验证命令行工具是否存在:($ 是终端中的命令提示符)

$ gcc
clang: error: no input files

如果收到-bash: gcc: command not found,则需要以standaloneXcode 的方式安装命令行工具(gcc)。

2。通过 Homebrew 安装 MySQL 客户端。

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

首先,从终端安装 Homebrew:

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

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

$ brew install mysql

您应该看到正在下载、倾倒、警告,最后是显示 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.在 RStudio 中从源代码安装 RMySQL。

到目前为止,所有步骤都在终端中完成。 虽然这一步也可以在终端中完成,但我将展示如何在 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 东西)和要链接的库(lib 东西)。

该指令告诉您设置 2 个环境变量 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 仓库或本地文件。

> 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() 实际上在终端(Unix shell)环境中运行R CMD INSTALL xxx。所以如果你喜欢终端方式,你也可以通过终端中的导出命令设置PKG_CPPFLAGSPKG_LIBS,然后运行R CMD INSTALL RMySQL_xxx.tar.gz从你有的源包手动安装已下载。

因此,对于第 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

【讨论】:

  • 瑞恩,你是个天才和救星!
  • 我赞同上面的评论!谢谢!
【解决方案2】:

我按照上述说明进行操作:

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")

希望这会有所帮助。

【讨论】:

  • 我在使用 OSX Yosemite 时收到了相同的错误消息。我要安装的软件包版本是 RMySQL 0.9-3。有什么想法吗?
【解决方案3】:

我在使用 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

【讨论】:

    【解决方案4】:

    您将在here 中找到完整的解决方案。您可能需要根据您的系统环境进行配置。它适用于我的

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

    【讨论】:

      【解决方案5】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-30
        • 2014-08-14
        • 2020-07-07
        • 1970-01-01
        • 2014-10-31
        • 1970-01-01
        相关资源
        最近更新 更多