简体   繁体   English

ModuleNotFoundError:没有名为“scapy”的模块

[英]ModuleNotFoundError: No module named 'scapy'

I can't import the module "scapy" in my virtual environment.我无法在我的虚拟环境中导入模块“scapy”。 I tried it with python 3.6.9 (which i have to use for my project) and python 3.7.我用 python 3.6.9(我必须用于我的项目)和 python 3.7 进行了尝试。 None of them versions did work.他们的版本都没有工作。

Import variants like导入变体,如

from scapy.all import *

or或者

import scapy

or或者

from scapy import IP, sr1, ICMP

all these did not work.所有这些都不起作用。

None of the other posts I found solved my problem.我发现的其他帖子都没有解决我的问题。

The installation via pip in the virtual env was successful.在虚拟环境中通过pip安装成功。 After that the module appears in the results of之后模块出现在结果中

pip list

I let printed out the paths, which python searches for modules and found, that the path to the scapy module wasn't in it, which is kinda interesting because isn't that the usual way one would expect using virtual envs...?!我打印出路径,python 搜索模块并发现其中没有 scapy 模块的路径,这有点有趣,因为这不是人们期望使用虚拟环境的通常方式......? ! Anyway, after adding this path:无论如何,添加此路径后:

import sys
sys.path.append('/home/username/Desktop/environments/my_env/bin/')

it also didn't work, even though the scapy binary is located in the same bin folder as python.它也不起作用,即使 scapy 二进制文件与 python 位于同一个 bin 文件夹中。

I already tried to reinstall ... basically everything.我已经尝试重新安装...基本上一切。

did you install scrapy by accident?你是不是不小心安装了scrapy? (scrapy instead of scapy)? (scrapy而不是scapy)?

好吧,它也发生在我身上,猜猜我有一个脚本保存为“scapy.py!这就是我的问题!吸取的教训:) 为脚本选择名称时要小心。

I was facing the same problem with python3.8 .我在使用 python3.8 时遇到了同样的问题。 I am a Kali Linux user and I was working on a project.我是 Kali Linux 用户,我正在做一个项目。 In that project I needed to import 'scapy' module.在那个项目中,我需要导入“scapy”模块。 So, normally I installed scapy with pip.所以,通常我用 pip 安装 scapy。 But it didn't run with python3.8 .但它没有与 python3.8 一起运行。 Then I noticed that, I could run the same python script with scapy module with python 2.7.然后我注意到,我可以使用带有 python 2.7 的 scapy 模块运行相同的 python 脚本。 Then I just simply got on a terminal and put these simple commands...然后我只是简单地进入终端并输入这些简单的命令......

sudo cp -r /usr/local/lib/python2.7/dist-packages/scapy /usr/local/lib/python3.8/dist-packages/

By this command I copied the scapy module from python 2.7's directory to python 3.8's directory.通过这个命令,我将 scapy 模块从 python 2.7 的目录复制到了 python 3.8 的目录。

If this doesn't work then follow this command also...如果这不起作用,那么也请遵循此命令...

sudo cp -r /usr/local/lib/python2.7/site-packages/scapy /usr/local/lib/python3.8/site-packages/

This solution worked for me.这个解决方案对我有用。 Hope this will work for you as well.希望这对你也有用。 Thanks.谢谢。

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

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