简体   繁体   中英

ImportError : No Module named scapy.all

I've tried to run this code using Pycharm in VirtualMachine Kali Linux and failed.

How to import scapy? I've also tried adding scapy to file > settings > ProjectInterpreter in Pycharm but it still doesn't work.

I'm sure I did install scapy using pip install scapy . What's the issue now?

这是我截图的图片

from scapy.all import *
        
def scan(ip):
    scapy.arping(ip)        

scan("10.0.2.1")

If someone is having the same issue after Udemy course. The exception is being thrown when you are trying to use it on python2, python3 network_scanner.py should solve the issue

first install the package with pip install scapy just use import scapy

or use from scapy import module_or_function_name

in your case use from scapy import arping

You don't need to use * here

The followings work without PyCharm:

from scapy.all import *

def scan(ip):
    scapy.layers.l2.arping(ip)

scan("10.0.2.1")

or

import scapy.all as scapy

def scan(ip):                                                                                                   
    scapy.arping(ip)

scan("10.0.2.1")

Just execute in terminal:

$ python3 network_scanner.py

Actually I had this problem and the answer is really easy. First of all you need to see which version of pip do you have. you can try which pip and also try with which pip3 . Next, when you open the terminal and and want to write your code if you have pyhton3 write on the command line ' python3 then from scapy.all import * will be okay to use.

In terminal type:

sudo mkdir /usr/dir/python2.7/dist-packages/scapy
cd /usr/lib/python3/dist-packages/
cd -avr scapy/* /usr/lib/python2.7/dist-packages/scapy

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM