简体   繁体   English

导入错误:没有名为 scapy.all 的模块

[英]ImportError : No Module named scapy.all

I've tried to run this code using Pycharm in VirtualMachine Kali Linux and failed.我尝试在 VirtualMachine Kali Linux 中使用 Pycharm 运行此代码但失败了。

How to import scapy?如何导入scapy? I've also tried adding scapy to file > settings > ProjectInterpreter in Pycharm but it still doesn't work.我也尝试在 Pycharm 中将 scapy 添加到文件 > 设置 > ProjectInterpreter但它仍然不起作用。

I'm sure I did install scapy using pip install scapy .我确定我确实使用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.如果有人在 Udemy 课程后遇到同样的问题。 The exception is being thrown when you are trying to use it on python2, python3 network_scanner.py should solve the issue当您尝试在 python2 上使用它时抛出异常, python3 network_scanner.py应该可以解决问题

first install the package with pip install scapy just use import scapy首先使用pip install scapy安装包只需使用import scapy

or use from scapy import module_or_function_name或使用from scapy import module_or_function_name

in your case use from scapy import arping在你的情况下使用from scapy import arping

You don't need to use * here你不需要在这里使用 *

The followings work without PyCharm:以下内容在没有 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.首先,您需要查看您拥有的是哪个版本的 pip。 you can try which pip and also try with which pip3 .你可以试试which pip也可以试试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.接下来,当你打开终端并想要编写你的代码时,如果你有 pyhton3 在命令行上写' python3那么from scapy.all import *就可以使用了。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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