Kernel install: No module named 'mkosi'

Whenever a new kernel or linux firmware is installed, I’m getting

dracut[I]: *** Creating initramfs image file '/efi/fa8aa03de6ce4398acdd2cd65f4e28b5/6.9.8-arch1-1/initrd' done ***
Traceback (most recent call last):
  File "/usr/lib/kernel/install.d/50-mkosi.install", line 12, in <module>
    from mkosi import identify_cpu
ModuleNotFoundError: No module named 'mkosi'
/usr/lib/kernel/install.d/50-mkosi.install failed with exit status 1.

and the system is unbootable. Note that for day-to-day work, I use python from a venv:

which python

and indeed

python -c "import mkosi"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'mkosi'

When using system Python, everything is fine:

/usr/bin/python -c "import mkosi; print(mkosi.__version__)"

That makes me think that, during the kernel installation process, my venv version of Python is called, not the system version. Perhaps that should be fixed.

Workaround: First go into a root env, su -, and upgrade or reinstall-kernels from there.

That isn’t something we package. It is part of mkosi.

However, looking at it, it seems to be doing the right thing. It has:

#!/usr/bin/env python3

That should always return the system python3.

If that is returning python from a venv, you should fix that.

How can I tell which python3 it returns?

At the python prompt you can type:

import sys

This indeed gives


because I source ~/venv/bin/activate in my .bashrc. I’d have assumed that sudo activities aren’t affected by that.

By default, your path is passed through to sudo.

You can change that if you add something like this via a drop-in in /etc/sudoers.d

Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.