错误信息
操作系统:ubuntu 20.04 64位
安装jpeg包的时候报错,错误信息:
> install.packages("jpeg")
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/jpeg_0.1-9.tar.gz'
Content type 'application/x-gzip' length 18596 bytes (18 KB)
==================================================
downloaded 18 KB
* installing *source* package ‘jpeg’ ...
** package ‘jpeg’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
gcc -std=gnu99 -std=gnu11 -I"/usr/share/R/include" -DNDEBUG -fpic -g -O2 -fdebug-prefix-map=/build/r-base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c read.c -o read.o
In file included from read.c:1:
rjcommon.h:11:10: fatal error: jpeglib.h: No such file or directory
11 | #include <jpeglib.h>
| ^~~~~~~~~~~
compilation terminated.
make: *** [/usr/lib/R/etc/Makeconf:168: read.o] Error 1
ERROR: compilation failed for package ‘jpeg’
* removing ‘/usr/local/lib/R/site-library/jpeg’
The downloaded source packages are in
‘/tmp/RtmpcHBCud/downloaded_packages’
Warning message:
In install.packages("jpeg") :
installation of package ‘jpeg’ had non-zero exit status
解决方法
直接使用命令行安装
首先搜索这个包的名称:
apt-cache search jpeg
一般R包的名称前面带有“r-cran-”,部分搜索结果:
r-cran-cairo - GNU R package "R Graphics Device using Cairo Graphics
r-cran-jpeg - GNU R package "Read and write JPEG images"
r-cran-magick - GNU R package "Advanced Graphics and Image-Processing in
r-cran-pdftools - GNU R package "Text Extraction, Rendering and Converting
安装 r-cran-jpeg 包
apt-get install r-cran-jpeg
返回R,用library试一下:
> library("jpeg")
>
就可以成功加载了
刚发现安装一个依赖库也可以解决这个问题
sudo apt-get install libjpeg62-dev