Python 导入错误:没有名为 scapy.all 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46602880/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ImportError: No module named scapy.all
提问by Michael Nielsen
I'm running macOS Sierra and Python 2.7.
我正在运行 macOS Sierra 和 Python 2.7。
In my terminal I've installed scapy with:
在我的终端中,我安装了 scapy:
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.
我试过和谷歌,并安装pcapy
和其他软件包 - 但没有运气。
采纳答案by Chen A.
ImportError: No module..
found error happens when Python doesn't find your module. So, where does it look for modules?
ImportError: No module..
当 Python 找不到您的模块时会发生 found 错误。那么,它在哪里寻找模块呢?
import os
print os.sys.path
Verify /usr/local/lib/python2.7/site-packages
is in that list. If not, append it
验证/usr/local/lib/python2.7/site-packages
在该列表中。如果没有,附加它
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.
os.sys.path.append('/usr/local/lib/python2.7/site-packages')
并尝试加载它。如果仍然不起作用,请尝试重新安装该模块,因为那里似乎存在问题。
回答by theautistic9
If you are using termux maybe you shoud try this:
如果您正在使用 termux,也许您应该试试这个:
pip2 install scapy.
回答by Kan1shka9
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'] >>> $
- Identify the location of scapy on you box
$ which scapy /usr/bin/scapy $
- 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 *
确定 Python 从中导入其库的位置
$ 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'] >>> $
- 确定你盒子上 scapy 的位置
$ which scapy /usr/bin/scapy $
- 您将不再收到导入错误
$ 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 *