pythonmacosscapy

ImportError: No module named scapy.all


I'm running macOS Sierra and Python 2.7.

In my terminal I've installed scapy with:

pip install scapy
Requirement already satisfied: scapy in /usr/local/lib/python2.7/site-packages

But running this:

from scapy.all import *

for pkt in sniff(iface='en0'):
    print pkt

Gives me this:

python test.py 
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from scapy.all import *
ImportError: No module named scapy.all

I've tried and Google around, and installed pcapy and other packages - but no luck.


Solution

  • ImportError: No module.. found error happens when Python doesn't find your module. So, where does it look for modules?

    import os
    print os.sys.path
    

    Verify /usr/local/lib/python2.7/site-packages is in that list. If not, append it

    os.sys.path.append('/usr/local/lib/python2.7/site-packages') and try to load it. If that still doesn't work, try re-installing the module, because it seems there is an issue there.