pythonpiplibpcap

Error "ModuleNotFoundError: No module named 'pylibpcap'"


I'm trying to use this Python libpcap library:

https://pypi.org/project/python-libpcap/

I have installed using:

sudo apt-get install libpcap-dev
pip3 install python-libpcap

but when I run the capture example code in script using sudo python3:

from pylibpcap.pcap import sniff

for plen, t, buf in sniff("my_interface", count=-1, promisc=1, out_file="pcap.pcap"):
    print("[+]: Payload len=", plen)
    print("[+]: Time", t)
    print("[+]: Payload", buf)

I get this error:

   from pylibpcap.pcap import sniff
ModuleNotFoundError: No module named 'pylibpcap'

How can I fix this/what's wrong?

I'm on Ubuntu 22.04.


Solution

  • I look up the manual for you quickly and tried to install the software on my own Mac to repeat the issue and help troubleshooting. But the installation was not even successful.

    I took another look at their website and it appears to only support up to python 3.7. Based on your sys info, it looks like you have python 3.10 installed.

    I suggested you to install python 3.6 or 3.7 then try this package again. Best luck!