環境
ubuntu desktop 22
python 3.11.2
やったこと
sudo apt install libsystemd-dev
そして、
pip install systemd
libsystemd-dev
が無事インストールされてもエラーが発生。
エラー文
$ pip install systemd
Collecting systemd
Using cached systemd-0.16.1.tar.gz (173 kB)
Preparing metadata (setup.py) ... done
Installing collected packages: systemd
DEPRECATION: systemd is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
Running setup.py install for systemd ... error
error: subprocess-exited-with-error
× Running setup.py install for systemd did not run successfully.
│ exit code: 1
╰─> [23 lines of output]
/home/tdzz/.pyenv/versions/3.11.2/lib/python3.11/site-packages/setuptools/_distutils/dist.py:264: UserWarning: Unknown distribution option: 'build_requires'
warnings.warn(msg)
running install
/home/tdzz/.pyenv/versions/3.11.2/lib/python3.11/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
running build
running build_py
creating build
creating build/lib.linux-x86_64-cpython-311
creating build/lib.linux-x86_64-cpython-311/systemd
copying systemd/journal.py -> build/lib.linux-x86_64-cpython-311/systemd
copying systemd/daemon.py -> build/lib.linux-x86_64-cpython-311/systemd
copying systemd/__init__.py -> build/lib.linux-x86_64-cpython-311/systemd
running build_ext
building 'systemd._daemon' extension
creating build/temp.linux-x86_64-cpython-311
creating build/temp.linux-x86_64-cpython-311/systemd
gcc -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/home/tdzz/.pyenv/versions/3.11.2/include/python3.11 -c systemd/_daemon.c -o build/temp.linux-x86_64-cpython-311/systemd/_daemon.o
systemd/_daemon.c:197:12: fatal error: longintrepr.h: No such file or directory
197 | #include "longintrepr.h"
| ^~~~~~~~~~~~~~~
compilation terminated.
error: command '/usr/bin/gcc' failed with exit code 1
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> systemd
note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
[notice] A new release of pip available: 22.3.1 -> 23.0.1
[notice] To update, run: pip install --upgrade pip
解決策
pypiにあるsystemd
モジュール自体が古いので、明確に言わないがpython3.9以上のバージョンは対応できません。
どうしてもsystemd
モジュールを使いたい場合は、python3.8を用意しましょう。
私の場合、pythonを3.8.10に切り替えると、利用可能になりました。
$ pyenv local 3.8.10
$ pip --version
pip 21.1.1 from /home/tdzz/.pyenv/versions/3.8.10/lib/python3.8/site-packages/pip (python 3.8)
$ pip install systemd
Collecting systemd
Using cached systemd-0.16.1.tar.gz (173 kB)
Using legacy 'setup.py install' for systemd, since package 'wheel' is not installed.
Installing collected packages: systemd
Running setup.py install for systemd ... done
Successfully installed systemd-0.16.1