Most of the answers here are helping you to install scapy on system-level and run with sudo access. Using sys.path
they're trying to add the path to the installed scapy location, basically, pip install packages in lib/python<any-version>/site-packages/
since python interpreter you're using to run the program containing the use of scapy python package don't have scapy in site-packages
that's why interpreter is raising ImportError: No module named scapy.all
!
I would recommend using a virtual environment manager to create a separate virtual environment of your choice of python version which could be 2.7 or 3.8 or whatever and then install and use scapy python package for your project inside your virtual environment. This will keep you system clean and the problem would be easily debuggable, you can delete this virtual environment later, and there will be no trace left of the project dependencies.
The use is very straight-forward:
assuming you've virtualenv
(external package like conda) installed, if not you can install
- if on python(version 2.x) :
pip install virtualenv
- if on python(version 3.x) :
python3 -m pip install virtualenv
Then,
create a virtual environment, you can name anything!
virtualenv --python=3.8 packet_sniffer_env38
activate virtual environment
source packet_sniffer_env38/bin/activate
simply install your dependencies, on your case scapy
pip install scapy
Now you can run a program using scapy, note you still need to use sudo access but this time you'll be using the python interpreter of the virtual environment and not of your system.
Also, you can check the libraries of this virtual environment, ./packet_sniffer_env38/lib/python3.8/site-packages
and you will find scapy
here!
sudo ./packet_sniffer_env38/bin/python <your_program_using_scapy>.py
you can have a look at the working use of scapy python package with virtualenv!