gpt4 book ai didi

r - 在小牛中安装 RMySQL

转载 作者:行者123 更新时间:2023-12-03 19:25:15 25 4
gpt4 key购买 nike

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

我可能会因为收到指示而为此大喊大叫,但行话已经超出了我的头脑,过去两个小时我一直在努力。任何人都可以帮忙吗?

最佳答案

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

  • OS X 小牛 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 ,您需要在 standalone 中安装命令行工具 (gcc)或 Xcode道路。

    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

    您应该看到 Downloading、Pouring、Caveats,最后是显示 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 无法找到要包含的头文件(包括内容)和要链接到的库(lib 内容)。

    该指令告诉您设置 2 个环境变量 PKG_CPPFLAGS PKG_LIBS 指示 include 和 lib 的位置。

    假设您已经使用 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
    >

    注: install.packages()在 R 中实际运行 R CMD INSTALL xxx在终端(Unix shell)环境中。所以如果你更喜欢终端方式,你也可以设置 PKG_CPPFLAGS PKG_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

    关于r - 在小牛中安装 RMySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24537257/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com