When you are using python nmap library, you may get this error: AttributeError: module ‘nmap’ has no attribute ‘PortScanner’. In this tutorial, we will introduce how to fix this error.
Look at this code:
port_scanner = nmap.PortScanner()
This code will report AttributeError.
How to fix this AttributeError?
As to us, we use pip to install nmap like this:
pip install nmap
This way can allow us to use python nmap library. However, it will cause AttributeError: module ‘nmap’ has no attribute ‘PortScanner’
We should uninstall nmap.
Uninstall nmap using pip
pip uninstall nmap
After you have uninstalled nmap, you can install python-nmap library.
We can use pip to install.
pip install -i https://mirrors.aliyun.com/pypi/simple/ python-nmap
Then you will find AttributeError: module ‘nmap’ has no attribute ‘PortScanner’ disappeared.