ImportError: No module named scapy.all

ぃ、小莉子 提交于 2020-04-08 15:01:51

问题


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.


回答1:


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.




回答2:


  1. Identify the location where Python is importing its libraries from

    $ python
    Python 2.7.15+ (default, Aug 31 2018, 11:56:52)
    [GCC 8.2.0] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os
    >>> print os.sys.path
    ['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/wx-3.0-gtk3']
    >>>
    $
    
    1. Identify the location of scapy on you box
    $ which scapy
    /usr/bin/scapy
    $
    
    1. You will no longer get the import error
    $ python
    Python 2.7.15+ (default, Aug 31 2018, 11:56:52)
    [GCC 8.2.0] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os
    >>> os.sys.path.append('/usr/bin/')
    >>> from scapy.all import *
    



回答3:


If you are using termux maybe you shoud try this:

pip2 install scapy.


来源:https://stackoverflow.com/questions/46602880/importerror-no-module-named-scapy-all

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!