如何在Ubuntu上安装R包“RNetCDF”和“ncdf”?

问题描述 投票:0回答:4

我想在 Ubuntu 中使用 R 软件包 RNetCDF 和 ncdf。

当我尝试

install.packages('RNetCDF')
install.packages('ncdf')
时,我收到类似的错误:

...
ncdf.c:3:20: fatal error: netcdf.h: No such file or directory
compilation terminated.
make: *** [ncdf.o] Error 1
ERROR: compilation failed for package ‘ncdf’
...
Warning message:
In install.packages("ncdf") :
  installation of package ‘ncdf’ had non-zero exit status

Ubuntu 存储库中的软件包

libnetcdf6
netcdf-bin
已安装。我还需要做其他事情吗?

r installation deb netcdf
4个回答
14
投票

您需要安装这些包的

-dev
才能获取编译包所需的标头。在这种情况下,您需要
libnetcdf-dev
udunits-bin
libudunits2-dev


7
投票

就我而言,需要 libudunits2-dev 包。

sudo apt-get install libudunits2-dev

由于我从源代码安装了 NetCDF,因此我必须手动指定 libinclude 文件夹

的位置
install.packages("/home/user/Downloads/RNetCDF_1.6.1-2.tar.gz", 
repos = NULL,
type="source",
dependencies=FALSE,
configure.args="--with-netcdf-include=/usr/local/netcdf-4.2.1-build/include --with-netcdf-lib=/usr/local/netcdf-4.2.1-build/lib")

1
投票

只是为了澄清,因为您最初的问题是在 R 中,并且修复是在 R 之外应用的。我最初尝试这样做

install.packages("libnetcdf-dev"),这不起作用。

相反,从 R 外部: sudo apt-get install libnetcdf-dev

这为我解决了问题。


1
投票

在 Ubuntu 20.04 LTS 中,可以使用 bash(shell/终端)命令 sudo apt install r-cran-ncdf4 安装 ncdf4 软件包(

取代 ncdf
),包括所有依赖项。同样,对于 RNetCDF,您可以使用
sudo apt install r-cran-rnetcdf

© www.soinside.com 2019 - 2024. All rights reserved.