Search code examples
pythonpython-3.xnetworkingnetfilter

why does installing netfilterqueue with sudo doesn't work when without sudo python found the module


when installing netfilterqueue with sudo i get no error but when executing the python code it says that there is no module but when doing the same command without sudo it says that the module is install but i need to use sudo to use the python code, i put all the command line that i get under.

with sudo

pi@raspberrypi:~/serveur/firewall $ sudo python3.5 -m  pip install -U git+https://github.com/kti/python-netfilterqueue
Collecting git+https://github.com/kti/python-netfilterqueue
  Cloning https://github.com/kti/python-netfilterqueue to /tmp/pip-26umdc4u-build
Installing collected packages: NetfilterQueue
  Running setup.py install for NetfilterQueue ... done
Successfully installed NetfilterQueue
pi@raspberrypi:~/serveur/firewall $ sudo python3.5 firewall.pyTraceback (most recent call last):
  File "firewall.py", line 1, in <module>
    from netfilterqueue import NetfilterQueue
ImportError: No module named 'netfilterqueue'

without sudo

pi@raspberrypi:~/serveur/firewall $ python3.5 -m pip install -U git+https://github.com/kti/python-netfilterqueue
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting git+https://github.com/kti/python-netfilterqueue
  Cloning https://github.com/kti/python-netfilterqueue to /tmp/pip-req-build-yad67c46
Building wheels for collected packages: NetfilterQueue
  Building wheel for NetfilterQueue (setup.py) ... done
  Created wheel for NetfilterQueue: filename=NetfilterQueue-0.8.1-cp35-cp35m-linux_armv7l.whl size=79256 sha256=7461466e6fb8ef7cf85d7d7351be96991273863d684aaac3360b3c97534cfa46
  Stored in directory: /tmp/pip-ephem-wheel-cache-ogtjqq3t/wheels/64/80/b2/4dc9e937d58cc96a143e886a09d951be89ad9d7315141d6c2c
Successfully built NetfilterQueue
Installing collected packages: NetfilterQueue
Successfully installed NetfilterQueue-0.8.1
WARNING: You are using pip version 20.2.2; however, version 20.2.3 is available.
You should consider upgrading via the '/usr/bin/python3.5 -m pip install --upgrade pip' command.
pi@raspberrypi:~/serveur/firewall $ ls
firewall.py
pi@raspberrypi:~/serveur/firewall $ python3.5 firewall.pyTraceback (most recent call last):
  File "firewall.py", line 8, in <module>
    nfqueue = NetfilterQueue()
  File "netfilterqueue.pyx", line 162, in netfilterqueue.NetfilterQueue.__cinit__ (netfilterqueue.c:4098)
OSError: Failed to bind family 2. Are you root?

Thanks for helping


Solution

  • So I don't know the netfilterqueue library, but based on the message I think what's happening is that the library is using a builtin C file that needs sudo access to run. There's a github issue here that might answer this question, but i'm not sure.