Fix Python AttributeError: module ‘nmap’ has no attribute ‘PortScanner’ – Python Tutorial

By | September 2, 2020

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.

AttributeError - module 'nmap' has no attribute 'PortScanner'

How to fix this AttributeError?

As to us, we use pip to install nmap like this:

pip install nmap

python 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.

Install python-nmap

We can use pip to install.

pip install -i https://mirrors.aliyun.com/pypi/simple/ python-nmap

python pip install python-nmap

Then you will find AttributeError: module ‘nmap’ has no attribute ‘PortScanner’ disappeared.

Leave a Reply