【问题标题】:fatal error installing systemfonts in jupyter R docker在 jupyter R docker 中安装 systemfonts 时出现致命错误
【发布时间】:2025-12-03 02:30:01
【问题描述】:

我在 docker 上运行 jupyterlabs 并想安装 rvg 包。其中一个依赖项是systemfonts,当我尝试使用install.packages("systemfonts") 安装它时,我得到:

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

所以我从 CRAN 下载了 tar.gz 文件并从文件中安装,但我收到了一个致命错误:

    > 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

我尝试关注此SO Post,输入sudo apt-get install -y libfreetype6 以获取freetype,但它已经是最新版本。我不确定还有什么可以尝试的,希望有人可以提供一些专业知识。谢谢。

【问题讨论】:

    标签: r jupyter-lab jupyter-irkernel


    【解决方案1】:

    搜索“ft2build.h: No such file or directory Ubuntu”会转到this issue on systemfonts library GitHub,其中显示了针对 Ubuntu 20.04 的编译错误的解决方法:

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

    这应该可以帮助您从tar.gz 源编译库。

    【讨论】:

    • 嗨@krassowski,我试过了,但收到了这条消息:Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package libfontconfig1-dev;然后我尝试不使用-devBuilding dependency tree Reading state information... Done libfontconfig1 is already the newest version (2.13.1-2ubuntu3). libfontconfig1 set to manually installed. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    • 那个 github 帖子提到通过 Brew 重新安装 freetype,我尝试安装免费类型,但它也已经是最新版本了。
    • 您使用的是哪个版本的 Ubuntu?
    • 我的意思是我很困惑,因为你说你使用了sudo apt-get,这看起来很像你在使用 Ubuntu,但你提到 Brew 听起来像 Mac,所以我不确定到底是什么您的 docker 映像(也不是您使用的 R 版本)。
    • 是的,docker 镜像基于 Ubuntu,VERSION="20.04.1 LTS (Focal Fossa)。您引用的 SO 帖子提到使用Brew 安装freetype。我只是在帖子中指出了这一事实。