Skip to contentSkip to conversation

ImportError: cannot import name '_selinux' from 'selinux' with swig-4.0.0

DISCUSSION Petr Lautrbach 1 participant 1 message May 16, 2019 SELinux security module

lore
Share & tools
lore
#0 lore raw

Hello all,

selinux python module can't be imported when it's built using swig-4.0.0:

Quoted 1 line
Quoted 1 line
Quoted 1 line

import selinux

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python3.7/site-packages/selinux/__init__.py",
line 13, in <module>
from . import _selinux
ImportError: cannot import name '_selinux' from 'selinux' (/usr/lib64/python3.7/site-packages/selinux/__init__.py)

Quoted 1 line
Quoted 1 line
Quoted 1 line

You can see it at [1]

The reason is that swig changed the way how it generates __init__.py. Now it uses:
from . import _selinux

I've started to rewrite libselinux in order not to build and install python bindings manually, but to use python distutils [2]. It still fails on travis but I was able to built it and use it on my local rawhide machine.

[1] https://groups.google.com/forum/#!topic/kernel-secnext/rGZxB39atVQ
[2] https://github.com/bachradsusi/SELinuxProject-selinux/commits/swig-use-python-distutils