繁体   English   中英

在 Linux 上安装 nloptr

[英]Installing nloptr on Linux

我正在尝试在没有互联网连接的 CentOS Linux 机器上安装 R 包nloptr ,如下所示:

install.packages("/home/ravi/nloptr_1.0.4.tar.gz", repos = NULL, type="source")

该命令依次在线查找以下文件

http://ab-initio.mit.edu/nlopt/nlopt-2.4.2.tar.gz

但是,这失败了,因为机器没有互联网连接。

我尝试了以下 stackoverflow 帖子中的建议:

在 Ubuntu 上本地安装 nloptr 的问题

我更改了 configure 和 configure.ac 文件中的 URL,如下所示:

NLOPT_URL="file:///home//ravi//${NLOPT_TGZ}"

但是,当我再次尝试安装软件包时出现以下错误:

> install.packages("/home/ravi/nloptr_1.0.4.tar.gz", repos = NULL, type="source")
* installing *source* package 'nloptr' ...
files 'configure', 'configure.ac' have the wrong MD5 checksums
ERROR: 'configure' exists but is not executable -- see the 'R Installation and Administration Manual'
* removing '/opt/vertica/R/library/nloptr'
Warning message:
In install.packages("/home/ravi/nloptr_1.0.4.tar.gz",  :
  installation of package '/home/ravi/nloptr_1.0.4.tar.gz' had non-zero exit status

有人可以指导我如何在本地安装这个 R 包吗?

更新 1

根据 Dirk 关于首先安装 nlopt 的建议,我按照以下页面中的说明进行操作:

http://ab-initio.mit.edu/wiki/index.php/NLopt_Installation

我安装了 nlopt 如下:

./configure --enable-shared
make
make install
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib

当我尝试在 R 中重新安装 nloptr 时,它不再查找 nlopt 链接,而是抛出以下错误:

Error in dyn.load(file, DLLpath = DLLpath, ...) :
  unable to load shared object '/opt/vertica/R/library/nloptr/libs/nloptr.so':
  /opt/vertica/R/library/nloptr/libs/nloptr.so: undefined symbol:   nlopt_set_maxtime
Error: loading failed
Execution halted
ERROR: loading failed
* removing '/opt/vertica/R/library/nloptr'
Warning message:
In install.packages("/home/ravi/nloptr_1.0.4.tar.gz",  :
  installation of package '/home/ravi/nloptr_1.0.4.tar.gz' had non-zero exit     status

更新 2

按照 Dirk 的建议,我查看了 ldconfig 命令并使用了以下参考:

http://codeyarns.com/2014/01/14/how-to-add-library-directory-to-ldconfig-cache/

我编辑了 /etc/ld.so.conf 文件,添加了包含共享库的目录 /usr/local/lib 并运行了 ldconfig 命令。 这添加了相关的共享库,如下所示:

libnlopt.so.0 (libc6,x86-64) => /usr/local/lib/libnlopt.so.0
libnlopt.so (libc6,x86-64) => /usr/local/lib/libnlopt.so

但是,当我尝试重新安装 nloptr 包时,我仍然遇到相同的共享对象错误。

有人可以指导我解决共享库错误吗?

当你说[t]his 命令依次在线查找以下文件时,你只得到了一半的故事。 我与实际 nloptr 包的维护者 Jelmer 一起修改了该包以执行以下操作:

  • 查找安装 libnlopt 库,如果找到,则使用它
  • 如果未找到,则返回旧行为并下载库

所以你可以简单地通过安装 nlopt

 sudo apt-get install libnlopt-dev

(或等效的sudo dpkg -i /media/....指向 USB 驱动器等 pp 中的文件),然后重新安装nloptr包。 它会起作用。 在我的机器上:

edd@max:~$ install.r nloptr         ## install.r is in littler
trying URL 'http://cran.rstudio.com/src/contrib/nloptr_1.0.4.tar.gz'
Content type 'application/x-gzip' length 353942 bytes (345 KB)
==================================================
downloaded 345 KB

* installing *source* package ‘nloptr’ ...
** package ‘nloptr’ successfully unpacked and MD5 sums checked
checking for g++... g++
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C++ preprocessor... g++ -E
checking whether we are using the GNU C++ compiler... (cached) yes
checking whether g++ accepts -g... (cached) yes
checking for pkg-config... yes
configure: Now testing for NLopt header file.
[...]
checking for nlopt.h... yes
configure: Suitable NLopt library found.
configure: creating ./config.status
config.status: creating src/Makevars
** libs
g++ -I/usr/share/R/include -DNDEBUG      -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g  -O3 -Wall -pipe -Wno-unused -pedantic  -c dummy.cpp -o dummy.o
gcc -I/usr/share/R/include -DNDEBUG      -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g  -O3 -Wall -pipe -pedantic -std=gnu99 -c nloptr.c -o nloptr.o
g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o nloptr.so dummy.o nloptr.o -lnlopt -lm -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/nloptr/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (nloptr)

The downloaded source packages are in
        ‘/tmp/downloaded_packages’
edd@max:~$ 

注意它是如何从找到 nlopt 安装的实际 R 包中只编译两个文件的。

我在没有直接访问 Internet 的生产机器上遇到了完全相同的问题,使用 Red Hat Enterprise Linux Server 6.6 版(圣地亚哥)。 上面提出的修正没有奏效:在系统上安装 nlopt 库时,随后尝试安装 nloptr 失败,并显示“nlopt_set_maxtime”错误。 我试图摆弄 nlopt 的编译选项,但无济于事。 我什至在具有 Internet 连接的 Ubuntu 机器上重现了该问题:我卸载了 nloptr,在系统上安装了 nlopt,然后 nloptr 安装失败。

最后我通过以下步骤解决了这个问题:

  1. 从操作系统中卸载 nlopt(确保将其彻底删除)。
  2. 手动下载nlopt-2.4.2.tar.gz并复制到/tmp/
  3. 手动下载nloptr_1.0.4.tar.gz到工作目录并解压; 这将创建目录“nloptr/”。
  4. 编辑“nloptr/configure”,注释掉该行

    $("${R_HOME}/bin/Rscript" --vanilla -e "download.file(url='${NLOPT_URL}', destfile='${NLOPT_TGZ}')")

    并插入一个新行:

    $("${R_HOME}/bin/Rscript" --vanilla -e "file.copy(from='/tmp/nlopt-2.4.2.tar.gz', to='${NLOPT_TGZ}')")

  5. 使用“R CMD INSTALL nloptr”安装。

我在 Ubuntu 上遇到了类似的问题。 除了按照Dirk 的回答安装 nlopt-dev 之外,我还必须安装 pkg-config:

sudo apt-get install pkg-config

希望这可以帮助。

如果您使用的是 CentOS(并且可以访问 Internet,但无法访问 nlopt 服务器),您可以先使用以下命令安装nlopt

yum install nlopt nlopt-devel

然后就可以正常安装nloptr

我在 RHEL 7.2 实例上设置 nloptr 时遇到了同样的问题。 对于使用 RHEL 的用户,您可以执行以下操作: 按相同顺序下载并安装以下 RPMS:

请注意,根据您的系统配置,这些 RPM 可能需要安装额外的依赖项。

发布此信息后,您可以使用 install.packages 实用程序直接安装 nloptr 或从 CRAN 下载源代码并按照之前回复中的建议从源代码安装。

希望这可以帮助!

基兰

如果您使用的是 AWS Linux,以下内容应该会有所帮助

yum --enablerepo=epel install NLopt-devel -y

我刚刚通过以下两个步骤在我的服务器上解决了这个问题:

  1. 安装libnlopt-devnlopt
sudo apt-get install libnlopt-dev
pip install nlopt
  1. 使用sudo R启动 R 并输入:
withr::with_makevars(c(PKG_LIBS='-lnlopt'),install.packages('nloptr'),assignment='+=')

我想我和你有同样的问题,我正在使用 CentOS 6.5 删除 nlopt 并在 R 中使用 install.packages() 安装 nloptr,将自动安装 nlopt。

我在解压缩的 nlopt 文件夹中使用以下命令删除了已安装的 nlopt。

make uninstall 

如果您曾尝试在 CentOS 中使用 epel 存储库并且已使用 yum 安装了 nlopt,请尝试:

yum remove nlopt

删除现有的 nlopt 后,我​​可以安装 nloptr

install.packages("nloptr")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM