Scapy.all import * does not work

后端 未结 5 983
遥遥无期
遥遥无期 2021-01-11 11:10

So, I wrote a little script in Ubuntu for scapy.

#!/usr/bin/env python
import sys
#from scapy.all import *
try 
   import scapy
   except ImportError:
              


        
5条回答
  •  再見小時候
    2021-01-11 11:37

    From looking at scapy source, the scapy package doesn't appear to import anything or define an __all__ in __init__. As a result, you need to explicitly import scapy.all (or from scapy import all) before you can from scapy.all import anything else from it, as it won't be in sys.modules yet. Note that this only has to happen once in your program flow though, as after the interpreter imports the module, it will be available to all code that executes from then on, regardless of where it is. Take a look at the Python docs on modules and how import, and specifically importing a package, works for more details.

    Edit: I think I see the problem now, I just was paying attention to the wrong part of your stack trace. Pretty sure what you are dealing with here is a name collision. Your file is named scapy.py, so when you import scapy from the context of that file, you are actually importing the file itself as a module. Since your file does not have a submodule named all (it can't, since it's not a package), you get the import error you are seeing. Try switching the name of your file to something that does not conflict with any packages or modules you wish to import inside it, and see if that works out better.

    By the way, note in your stack traces that your import is actually essentially recursively calling your one file. That should be a clue that something has gone haywire in the import process.

提交回复
热议问题