WSLでR
(r-base
)をインストールしてさらにtidyverse
というパッケージをインストールしようとして
install.packages("tidyverse")
てやったら,なんか
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to create bus connection: Host is down
って怒られた.
色々調べるとlinuxだとカーネルがまず呼び出すプロセスとしてsystemd
が一般的で,これに依存してる?ものがあるらしい.
基本的に大体のディストロで/sbin/init
がsystemd
にリンクしている.
WSLにインストールしたディストロもsystemdが存在し,/sbin/init
がsystemd
にリンクしているが,実際にWSLから起動する際は/init
が呼び出され,これはMicroSoftが独自に開発してるものらしい?
これに対し多くのissueが建てられており,WSL2ではsystemd
を呼び出すようなテクニックが共有されている.
https://shikiyura.com/2021/07/run_systemd_as_pid_1_on_wsl2_202107/
https://github.com/arkane-systems/genie
https://stackoverflow.com/questions/55579342/why-systemd-is-disabled-in-wsl
しかし,大抵WSL2の解決策ばかりでWSL1向けの記事は見つからない.自分としてはシリアルポートがWSL2だと使えないのでWSL1をいまだに使っている.
なのでsystemdが要求されている場合だけWSL2を使おうかとあきらめかけたが以下のような記事を見つけた
https://dev.to/bowmanjd/you-probably-don-t-need-systemd-on-wsl-windows-subsystem-for-linux-49gn
これによるとなんかsystemd
がなくても動くと書いてある.
半信半疑,R
を起動してlibrary(tidyverse)
としてみてもやはり動かない.
一応R
からではなくapt install r-cran-tidyverse
とかしてインストール自体はできる模様なので,こちらでインストールを試みた.(他にもr-cran-xml2
とかもこれでインストールした)
もう一度R
を起動してlibrary(tidyverse)
とすると,
> library(tidyverse)
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to create bus connection: Host is down
── Attaching packages ──────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
✔ ggplot2 3.3.5 ✔ purrr 0.3.4
✔ tibble 3.1.4 ✔ dplyr 1.0.7
✔ tidyr 1.1.3 ✔ stringr 1.4.0
✔ readr 2.0.1 ✔ forcats 0.5.1
── Conflicts ─────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
Warning message:
In system("timedatectl", intern = TRUE) :
running command 'timedatectl' had status 1
となってやはりsystemd
がPID1
ではない云々という怒られは生じるが,一応ライブラリの読み込み自体はできた.単に読み込めたっぽいだけだと困るのでtidyverse
の機能を利用してみる以下のようなコマンドを入力してみた
> df <- read_csv("https://www.nstac.go.jp/SSDSE/data/2021/SSDSE-B-2021.csv", locale = locale(encoding="CP932"), skip=1)
> subdf <- df %>% select(年度, 都道府県, 総人口) %>%
+ filter(都道府県 %in% c("東京都")) %>%
+ filter(年度==2018 | 年度==2017 | 年度==2016 | 年度==2015)
> ggplot(subdf, aes(x=年度, y=総人口))+geom_bar(stat="identity") + theme_light()
動いた
よく分かんないけどたぶんR
内でinstall.packages
でインストールした際のエラーのメインはsystemd
とかではなく,mv: cannot move ... Permission denied
のだったのかもしれない.
というわけでsystemd
がPID1
じゃないと怒られても動くことはあるという話でした.
追記
そもそもR
内でtidyverse
をインストールするときに怒られる理由がxml2
とかの依存パッケージがインストールできないからであるが,かといって
現状apt install
でインストールできるr-cran-xml2
のバージョンがちょっと古くてこれは使えんって怒られが生じる,
R
内でinstall.packages("xml2")
をすればよいのだが,これは何か途中のmv
の作業でパーミッション関係で怒られる.
chmod
でもすればよいのかもしれないが,以下の記事によると,オプションを付けるだけでパーミッションエラーを回避してくれるみたい
https://stackoverflow.com/questions/14382209/r-install-packages-returns-failed-to-create-lock-directory/14389028#14389028
というわけで
> install.packages("xml2", dependencies=TRUE, INSTALL_opts='--no-lock')
てやったらすんなりできた.これでさらに
> install.packages("tidyverse")
てやったら,途中めちゃめちゃsystemd
が~って怒られるけど最終的にはちゃんとインストールできたっぽい
Installing package into ‘~/R/x86_64-pc-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/tidyverse_1.3.1.tar.gz'
Content type 'application/x-gzip' length 702779 bytes (686 KB)
==================================================
downloaded 686 KB
* installing *source* package ‘tidyverse’ ...
** package ‘tidyverse’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to create bus connection: Host is down
Warning in system("timedatectl", intern = TRUE) :
running command 'timedatectl' had status 1
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to create bus connection: Host is down
Warning in system("timedatectl", intern = TRUE) :
running command 'timedatectl' had status 1
** testing if installed package can be loaded from final location
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to create bus connection: Host is down
Warning in system("timedatectl", intern = TRUE) :
running command 'timedatectl' had status 1
** testing if installed package keeps a record of temporary installation path
* DONE (tidyverse)
The downloaded source packages are in
‘/tmp/RtmpHuYGe4/downloaded_packages’
というわけでやっぱ
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to create bus connection: Host is down
は無視してよいかもしれない