I am having issues when importing scapy in my Ubuntu virtual machine.
I can easily use from scapy.all import *
in the terminal.
I am using Visual Studio Code and when I hover over scapy, right click and go to defintion, it takes me to the scapy file.
Here's what solutions I've seen and tried:
My filename(or any filename in the folder) is not "scapy.py".
I've installed scapy directly from the website, used "sudo apt-get install python3-scapy" and also tried with "pip install scapy". None of which changed anything.
If I run another python file (without "sudo" and with "from scapy.all import *") it runs fine. But there is an import issue when I use "sudo".
I tried to do the following to solve my issue:
sudo mkdir /usr/lib/python2.7/dist-packages/scapy
cd /usr/lib/python3/dist-packages/
cp -avr scapy/* /usr/lib/python2.7/dist-packages/scapy
\\ This also didnt work out.
I also thought maybe I messed up some of the module files. So I tried doing everything on a new VirtualBox image. But that also failed.
I can type "scapy" in the terminal and it opens up fine.
my python version is 3.8.10
Scapy version: 2.4.5
I've been stuck on this for 4 days. Please help.
it's recommended to use virtualenv , it will resolve the conflict if you have multiple python versions.
create a virtual environment, by the following commands
virtualenv env -p python3
then activate it
source env/bin/activate
then install scapy using pip:
pip install scapy
and try to import the library from there.
Packages installed on a non-root user are not installed system wide, thus there is an import issue when you run the script as a root user
Some solutions that can be used:
sudo su
pip install scapy
sudo python3 script.py
demo@stack:~/demo$ virtualenv venv
demo@stack:~/demo$ source venv/bin/activate
(venv) demo@stack:~/demo$ pip install scapy
(venv) demo@stack:~/demo$ sudo python3 script.py
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.