-1

I am on mac (first time) and using pycharm and visual code.

On pycharm, I am using a venv, have installed scapy and can see it is installed in the interpreter package manager and there is no red line under "import scapy". the issue arises when I try and import anything from that package "from scapy import UDP" or use anything in scapy "scapy.UDP". ----respective errors shown below.

ImportError: cannot import name 'UDP' from 'scapy' (/Users/{KEVIN}/PycharmProjects/UDP/venv/lib/python3.9/site-packages/scapy/__init__.py)

AttributeError: module 'scapy' has no attribute 'UDP'

As a side not I tried using visual code and system python, and the code runs with no issues, but i cant right click on UDP() and jump to the class definition it says not definition found? I feel like this has to be a mac related issue but i can't seem to figure it out.

MisterMiyagi
  • 44,374
  • 10
  • 104
  • 119
Kevin Riordan
  • 81
  • 2
  • 8

2 Answers2

1

UDP is not directly under scapy, you need to do

from scapy.layers.inet import UDP

then you can right click on UDP() and jump to the class definition.

Following two imports worked for me as well :

venv$ python
Python 3.8.10 (default, Sep 28 2021, 16:10:42) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from scapy.ansmachine import AnsweringMachine
>>> from scapy.all import UDP
>>>

Please double check you scapy installation.

Philippe
  • 20,025
  • 2
  • 23
  • 32
  • Thank you @Philippe! I spent way to much time for something so trivial. This solved all issues in both IDEs. but can you explain why "from scapy.all import UDP" doesnt work? – Kevin Riordan Oct 17 '21 at 18:08
  • This answer only worked once, running it again produced error: ImportError: cannot import name 'AnsweringMachine' from partially initialized module 'scapy.ansmachine' (most likely due to a circular import) – Kevin Riordan Oct 17 '21 at 18:21
-1

Try: from scapy.all import * from https://scapy.readthedocs.io/en/latest/functions.html

Does this work?

seveneights
  • 425
  • 5
  • 15
  • So it will run in pycharm venv, but it still doesn't see the function UDP(). normally I could click on UDP() to see the constructor but instead I see "Cannot find reference 'UDP' in 'imported module scapy | imported module scapy | __init__.py' " – Kevin Riordan Oct 17 '21 at 18:03
  • If I do "from scapy.all import UDP" it still runs but it shows red line under UDP that when hovered above shows, "Cannot find reference 'UDP' in 'all.py' " – Kevin Riordan Oct 17 '21 at 18:05