rjupyter-labjupyter-irkernel

fatal error installing systemfonts in jupyter R docker


I am running jupyterlabs on docker and wanted to install the rvg package. One of the dependencies are systemfonts, and when I tried to install this using install.packages("systemfonts") I get:

Warning: unable to access index for repository https://cran.yu.ac.kr/src/contrib:
  cannot open URL 'https://cran.yu.ac.kr/src/contrib/PACKAGES'
Warning message:
package ‘systemfonts’ is not available for this version of R

A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages

So I downloaded the tar.gz file from CRAN and installed from file, but I get a fatal error:

    > install.packages("systemfonts_1.0.2.tar.gz", repo = NULL, type = "source")
* installing *source* package ‘systemfonts’ ...
** package ‘systemfonts’ successfully unpacked and MD5 sums checked
** using staged installation
Using PKG_CFLAGS=
Using PKG_LIBS=-lfontconfig -lfreetype
** libs
rm -f systemfonts.so caches.o cpp11.o dev_metrics.o font_matching.o font_registry.o ft_cache.o string_shape.o font_metrics.o font_fallback.o string_metrics.o emoji.o cache_store.o init.o unix/FontManagerLinux.o
x86_64-conda-linux-gnu-c++ -std=gnu++11 -I"/opt/conda/lib/R/include" -DNDEBUG  -I'/opt/conda/lib/R/library/cpp11/include' -DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem /opt/conda/include -I/opt/conda/include -Wl,-rpath-link,/opt/conda/lib   -fpic  -fvisibility-inlines-hidden  -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /opt/conda/include -fdebug-prefix-map=/home/conda/feedstock_root/build_artifacts/r-base-split_1607284869564/work=/usr/local/src/conda/r-base-4.0.3 -fdebug-prefix-map=/opt/conda=/usr/local/src/conda-prefix  -c caches.cpp -o caches.o
In file included from caches.h:7,
                 from caches.cpp:1:
ft_cache.h:9:10: fatal error: ft2build.h: No such file or directory
    9 | #include <ft2build.h>
      |          ^~~~~~~~~~~~
compilation terminated.
make: *** [/opt/conda/lib/R/etc/Makeconf:181: caches.o] Error 1
ERROR: compilation failed for package ‘systemfonts’
* removing ‘/opt/conda/lib/R/library/systemfonts’
Warning message:
In install.packages("work/corehead_data/systemfonts_1.0.2.tar.gz",  :
  installation of package ‘work/corehead_data/systemfonts_1.0.2.tar.gz’ had non-zero exit status

I tried to follow this SO Post, by typing in sudo apt-get install -y libfreetype6 to get freetype, but it is already the newest version. I'm not sure what else to try, hopefully someone can provide some expertise. Thanks.


Solution

  • Searching for "ft2build.h: No such file or directory Ubuntu" leads to this issue on systemfonts library GitHub where a workaround for the compilation error for Ubuntu 20.04 is shown:

    sudo apt-get update
    sudo apt-get install libfontconfig1-dev
    

    This should help you to compile library from the tar.gz source.