更多麻烦在 ubuntu 16.04 上安装 rgdal

More trouble Installing rgdal on ubuntu 16.04

这个安装 rgdal 的问题在已经发布的其他类似问题中没有得到解决。我使用 http://www.sarasafavi.com/installing-gdalogr-on-ubuntu.html and also decribed in other answers like this 上的建议安装了 gdal,这意味着来自 ppa:ubuntugis.

然后当我尝试安装 rgdal 时出现以下错误

> install.packages("rgdal")
Installing package into ‘/home/leonardo/R/x86_64-pc-linux-gnu-library/3.5’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/rgdal_1.3-4.tar.gz'
Content type 'application/x-gzip' length 1664774 bytes (1.6 MB)
==================================================
downloaded 1.6 MB

* installing *source* package ‘rgdal’ ...
** package ‘rgdal’ successfully unpacked and MD5 sums checked
configure: R_HOME: /usr/lib/R
configure: CC: gcc -std=gnu99
configure: CXX: g++
configure: C++11 support available
configure: rgdal: 1.3-4
checking for /usr/bin/svnversion... no
configure: svn revision: 766
checking for gdal-config... /home/leonardo/anaconda3/bin/gdal-config
checking gdal-config usability... yes
configure: GDAL: 2.2.2
checking GDAL version >= 1.11.4... yes
checking gdal: linking with --libs only... no
checking gdal: linking with --libs and --dep-libs... no
/usr/bin/x86_64-linux-gnu-ld: warning: libproj.so.12, needed by /home/leonardo/anaconda3/lib/libgdal.so, not found (try using -rpath or -rpath-link)
/usr/bin/x86_64-linux-gnu-ld: warning: libpoppler.so.71, needed by /home/leonardo/anaconda3/lib/libgdal.so, not found (try using -rpath or -rpath-link)
/usr/bin/x86_64-linux-gnu-ld: warning: libxerces-c-3.2.so, needed by /home/leonardo/anaconda3/lib/libgdal.so,

...

500 lines more

...

/home/leonardo/anaconda3/lib/libgeos_c.so: undefined reference to `geos::geom::PrecisionModel::PrecisionModel(double)'
collect2: error: ld returned 1 exit status
configure: Install failure: compilation and/or linkage problems.
configure: error: GDALAllRegister not found in libgdal.
ERROR: configuration failed for package ‘rgdal’
* removing ‘/home/leonardo/R/x86_64-pc-linux-gnu-library/3.5/rgdal’
Warning in install.packages :
  installation of package ‘rgdal’ had non-zero exit status

我之前安装的 python anaconda 似乎有问题,我使用

删除了 anaconda python gdal 包
conda remove gdal

但问题依然存在

解决此问题的唯一方法是完全删除 anaconda 安装,按照 https://conda.io/docs/user-guide/install/linux.html#uninstalling-anaconda-or-miniconda 上的说明对 ubuntu 16.04 进行一些小的修改,您必须打开终端并删除 anaconda 安装目录:

rm -rf ~/anaconda3

rm -rf ~/.condarc ~/.conda ~/.continuum

编辑 ~/.bashrc 以从您的 PATH 环境变量中删除 anaconda 目录。

之后安装rgdal

install.packages("rgdal")

没有问题。