在 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
但是,这失败了,因为没有互联网连接到机器。
我尝试了以下 Whosebug post 的建议:
我更改了配置中的 URL 和 configure.ac 文件如下:
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 link 而是抛出以下错误:
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]他的命令依次在线查找以下文件 你只得到了一半的故事。我与实际 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" 错误。我尝试 fiddle 使用 nlopt 的编译选项,但无济于事。我什至在 Ubuntu 一台连接互联网的机器上重现了这个问题:我卸载了 nloptr,在系统上安装了 nlopt,然后 nloptr 安装失败。
最后我通过以下步骤解决了这个问题:
- 从操作系统中卸载 nlopt(确保已彻底删除)。
- 手动下载nlopt-2.4.2.tar.gz复制到/tmp/
- 手动下载nloptr_1.0.4.tar.gz到工作目录并解压;这将创建目录 "nloptr/".
编辑 "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}')")
安装 "R CMD INSTALL nloptr"。
我想我和你有同样的问题,我使用的是 CentOS 6.5
在 R 中删除 nlopt 并使用 install.packages() 安装 nloptr,将自动安装一个 nlopt。
我在解压的 nlopt 文件夹中使用以下命令删除了已安装的 nlopt。
make uninstall
如果您曾尝试在 CentOS 中使用 epel 存储库并使用 yum 安装了 nlopt,请尝试:
yum remove nlopt
删除现有的 nlopt 后,我可以使用
安装 nloptr
install.packages("nloptr")
我在 RHEL 7.2 实例上设置 nloptr 时遇到了同样的问题。对于使用 RHEL 的用户,您可以执行以下操作:
按相同顺序下载并安装以下 RPMS:
NLopt-2.4.2-2.el7.x86_64.rpm- https://pkgs.org/centos-7/epel-x86_64/NLopt-2.4.2-2.el7.x86_64.rpm.html
NLopt-devel-2.4.2-2.el7.x86_64.rpm - https://pkgs.org/centos-7/epel-x86_64/NLopt-devel-2.4.2-2.el7.x86_64.rpm.htm
请注意,根据您的系统配置,这些 RPM 可能需要安装其他依赖项。
Post 您可以使用 install.packages 实用程序直接安装 nloptr 或从 CRAN 下载源代码并按照之前回复中的建议从源代码安装。
希望对您有所帮助!
基兰
如果您使用的是 CentOS(并且可以访问互联网,但无法访问 nlopt 服务器),您可以先使用
安装 nlopt
yum install nlopt nlopt-devel
然后就可以正常安装nloptr
了
我在 Ubuntu 上遇到了类似的问题。除了将 nlopt-dev 安装为 ,我还必须安装 pkg-config:
sudo apt-get install pkg-config
希望对您有所帮助。
如果您使用的是 AWS Linux,以下内容应该对您有所帮助
yum --enablerepo=epel install NLopt-devel -y
我刚刚通过以下两个步骤在我的服务器上解决了这个问题:
- 安装
libnlopt-dev
和 nlopt
以及
sudo apt-get install libnlopt-dev
pip install nlopt
- 使用
sudo R
启动 R 并输入:
withr::with_makevars(c(PKG_LIBS='-lnlopt'),install.packages('nloptr'),assignment='+=')
我正在尝试在没有互联网连接的 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
但是,这失败了,因为没有互联网连接到机器。
我尝试了以下 Whosebug post 的建议:
我更改了配置中的 URL 和 configure.ac 文件如下:
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 link 而是抛出以下错误:
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]他的命令依次在线查找以下文件 你只得到了一半的故事。我与实际 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" 错误。我尝试 fiddle 使用 nlopt 的编译选项,但无济于事。我什至在 Ubuntu 一台连接互联网的机器上重现了这个问题:我卸载了 nloptr,在系统上安装了 nlopt,然后 nloptr 安装失败。
最后我通过以下步骤解决了这个问题:
- 从操作系统中卸载 nlopt(确保已彻底删除)。
- 手动下载nlopt-2.4.2.tar.gz复制到/tmp/
- 手动下载nloptr_1.0.4.tar.gz到工作目录并解压;这将创建目录 "nloptr/".
编辑 "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}')")
安装 "R CMD INSTALL nloptr"。
我想我和你有同样的问题,我使用的是 CentOS 6.5 在 R 中删除 nlopt 并使用 install.packages() 安装 nloptr,将自动安装一个 nlopt。
我在解压的 nlopt 文件夹中使用以下命令删除了已安装的 nlopt。
make uninstall
如果您曾尝试在 CentOS 中使用 epel 存储库并使用 yum 安装了 nlopt,请尝试:
yum remove nlopt
删除现有的 nlopt 后,我可以使用
安装 nloptrinstall.packages("nloptr")
我在 RHEL 7.2 实例上设置 nloptr 时遇到了同样的问题。对于使用 RHEL 的用户,您可以执行以下操作: 按相同顺序下载并安装以下 RPMS:
NLopt-2.4.2-2.el7.x86_64.rpm- https://pkgs.org/centos-7/epel-x86_64/NLopt-2.4.2-2.el7.x86_64.rpm.html
NLopt-devel-2.4.2-2.el7.x86_64.rpm - https://pkgs.org/centos-7/epel-x86_64/NLopt-devel-2.4.2-2.el7.x86_64.rpm.htm
请注意,根据您的系统配置,这些 RPM 可能需要安装其他依赖项。
Post 您可以使用 install.packages 实用程序直接安装 nloptr 或从 CRAN 下载源代码并按照之前回复中的建议从源代码安装。
希望对您有所帮助!
基兰
如果您使用的是 CentOS(并且可以访问互联网,但无法访问 nlopt 服务器),您可以先使用
安装nlopt
yum install nlopt nlopt-devel
然后就可以正常安装nloptr
了
我在 Ubuntu 上遇到了类似的问题。除了将 nlopt-dev 安装为
sudo apt-get install pkg-config
希望对您有所帮助。
如果您使用的是 AWS Linux,以下内容应该对您有所帮助
yum --enablerepo=epel install NLopt-devel -y
我刚刚通过以下两个步骤在我的服务器上解决了这个问题:
- 安装
libnlopt-dev
和nlopt
以及
sudo apt-get install libnlopt-dev
pip install nlopt
- 使用
sudo R
启动 R 并输入:
withr::with_makevars(c(PKG_LIBS='-lnlopt'),install.packages('nloptr'),assignment='+=')