获取错误:attributeError:模块' nmap'没有属性' portscanner'
我一直在寻找如何解决这个Python问题的答案:
属性错误:模块“nmap”没有属性“PortScanner”
我想了解有关端口扫描的更多信息,但我什至无法在我正在使用的 Visual Studio Code 上安装该模块。我已经尝试了我和许多人能想到的一切:
- 卸载并重新安装 python-nmap 以及 nmap (因为它们是互连的)。
- 我尝试过重命名模块本身。
- 我已经在不同的 IDE 上启动了我的代码,
- 我创建了一个单独的文件夹并将模块和我的项目放在那里。
到目前为止没有成功..
这是我的代码:
import nmap
nm = nmap.PortScanner()
nm.scan('127.0.0.1', '22-443')
和输出:
/usr/local/bin/python3 /Users
/user2132/Desktop/PYTHONProjects/portscannning.py
Traceback (most recent call last):
File "/Users/user2132/Desktop/PYTHONProjects/portscannning.py", line 3, in <module>
nm = nmap.PortScanner()
AttributeError: module 'nmap' has no attribute 'PortScanner'
接下来我可以尝试什么?
PS我使用的是MacOS
I have been seeking for answers of how to fix this Python problem:
AttributeError: module 'nmap' has no attribute 'PortScanner'
I wanted to learn more about port-scanning but I couldn't even install the module on Visual Studio Code, which I am using. I've tried everything that I and many people can think of:
- Uninstalled and reinstalled python-nmap as well as just nmap (since they are interconnected).
- I've tried renaming the module itself.
- I've launched my code on different IDEs
- I've created a separate folder and put modules and my project there.
No success so far..
This is my code:
import nmap
nm = nmap.PortScanner()
nm.scan('127.0.0.1', '22-443')
and the output:
/usr/local/bin/python3 /Users
/user2132/Desktop/PYTHONProjects/portscannning.py
Traceback (most recent call last):
File "/Users/user2132/Desktop/PYTHONProjects/portscannning.py", line 3, in <module>
nm = nmap.PortScanner()
AttributeError: module 'nmap' has no attribute 'PortScanner'
What can I try next?
P.S. I am using MacOS
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我能够重现该错误。问题出在
nmap
库上。pip install nmap
安装nmap python 库
,但python-nmap
需要nmap 二进制文件
,而且nmap python 库与 python-nmap 冲突,因为它们共享相同的模块名称。正确的
nmap
可以从Nmap的官方下载页面安装,请按照步骤操作步骤
1. 卸载库
步骤 2. 安装
python-nmap
步骤 3. 检查
nmap
是否已安装到您的系统中步骤 3. 如果已安装,请继续下一步步骤,如果没有:
转至Nmap官方下载页面,下载并安装适合您操作系统的nmap。
请确保在安装过程中选择了
添加到PATH
选项。步骤 4. 重新启动系统(重新启动计算机)
在终端中使用
which nmap
命令检查nmap
安装。之后您可以检查
PortScanner
是否在nmap
中。返回
最终测试
返回
I was able to reproduce the error. The problem was with the
nmap
library.pip install nmap
installsnmap python library
butpython-nmap
requiresnmap binary
, moreovernmap
python library conflicts withpython-nmap
because they share same module name. The correctnmap
could be installed from Nmap's official download pagePlease follow the steps below:
Step 1. uninstall libraries
Step 2. install
python-nmap
Step 3. Check if
nmap
installed into your systemStep 3. If it is installed, continue to the next step, if not:
Go to Nmap's official download page, download and install nmap for your OS.
Please make sure that
add to PATH
option is selected during installation.Step 4. Reboot your system (restart computer)
Check
nmap
installation withwhich nmap
command in terminal.After that you can check if
PortScanner
is innmap
.Returns
Final test
Returns
尝试Ctrl+Shift+P,类型Env,然后创建一个新的环境,然后添加
py -3 -m venv .venv .venv
,然后按Enter。Try Ctrl+Shift+P, type env, then create a new environment and add
py -3 -m venv .venv
and press Enter.