0

I am working on packets in my linux iptable , so i need to work over them in python. To get the packets in my iptable into python , i decided to use netfilterqueue.However , i run into error when i want to use it. The error is : ModuleNotFoundError: No module named 'netfilterqueue'

However , this module is installed.

I followed up each process in its webpage. I have GCC C compiler , i installed "apt-get install build-essential python-dev libnetfilter-queue-dev" , and "pip install NetfilterQueue".

When i run the "pip install NetfilterQueue" ,second time , it says that :

$ pip install NetfilterQueue

Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: NetfilterQueue in /home/salmon/.local/lib/python3.10/site-packages      (1.0.0)

When i go to the directory , i see that i have "netfilterqueue " and "NetfilterQueue-1.0.0.dist-info" directories , so i managed to download them.

I also download it in Pycharm without any problem. However , when i want to import it into my codes , it gives the error above.

I tried to restart both my main computer and virtualbox , but nothing is changed.

Can you help me fix this situation. I use Python 3.10.9 , pip 23.0 ,and vmware16 as virtualbox ,Kali Linux 2022.4

IMPORTANT ADDENTUM: When i open python using terminal , i can import it successfuly. I can see the inside of it using "dir()" function and learn about functions using "help()" function. However , when i try to run my code , i encounter with mentioned error ,thats ,importing the module error.

>>> import netfilterqueue
>>> dir(netfilterqueue)
['COPY_META', 'COPY_NONE', 'COPY_PACKET', 'NetfilterQueue', 'PROTOCOLS', 
'Packet', 'VERSION', '__builtins__', '__cached__', '__doc__', 
'__file__', '__loader__', '__name__', '__package__', '__path__', 
'__spec__', '__version__', '_impl', '_version']

>>>print(netfilterqueue)
 <module 'netfilterqueue' from '/home/salmon/.local/lib/python3.10/site- 
   packages/netfilterqueue/__init__.py'>

As you see , the module is used in terminal , but when i try to run the code using "sudo python 'filename'" , it gives " ModuleNotFoundError: No module named 'netfilterqueue'"

2
  • python -m pip install netfilterqueue , python filename.py Commented Feb 1, 2023 at 21:59
  • @sahasrara62 it did not work , i have to run it as root user , so i said sudo python filename.py , but it gave the same error Commented Feb 1, 2023 at 22:46

1 Answer 1

1

This is the operative part that was missing in your original post:

but when i try to run the code using "sudo python 'filename'"

That's because your users python env is different from root's.

root != salmon

One way to deal with this would be to do the pip install ... as root, system-globally.

Alternatively you could try to preserve your own environment when doing the sudo bit ...

sudo -E python 'filename'

Sign up to request clarification or add additional context in comments.

3 Comments

i said sudo pip install Netfilterqueue ,but it gave installing error
Without seeing the actual error I can't tell you much; you could try to preserve your own environment when doing the sudo bit ... sudo -E python 'filename' @SalmonFish
your second solution worked , please add it to your answer part

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.