Error import nmap into python

5.3k views Asked by At

I installed nmap module for python. While i was importing nmap,it received error. This error is attribute error.

Command line:

root@harun:~/Desktop# python nmap.py

Traceback (most recent call last):
   File "nmap.py", line 2, in <module>
    import nmap
   File "/root/Desktop/nmap.py", line 3, in <module>
    nm = nmap.PortScanner()
AttributeError: 'module' object has no attribute 'PortScanner'

this code is:

!/usr/bin/env python

import nmap
nm = nmap.PortScanner()

I changed code this:

!/usr/bin/env python

from nmap import nmap
nm = nmap.PortScanner()

But it received same error.

one more changed:

!/usr/bin/env python
 import nmap
 directory=dir(nmap)
 print directory

this received:

 root@harun:~/Desktop# python nmap.py
 ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'nmap']
 ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'directory', 'nmap']

But normally:

 root@harun:~# python
 >>> dir(nmap)

['PortScanner', 'PortScannerAsync', 'PortScannerError', 'PortScannerHostDict', 'PortScannerYield', 'Process', '__author__', '__builtins__', '__doc__', '__file__', '__last_modification__', '__name__', '__package__', '__path__', '__version__', 'collections', 'convert_nmap_output_to_encoding', 'csv', 'io', 'nmap', 'os', 're', 'shlex', 'string', 'subprocess', 'sys', 'types', 'xml']

Could you tell me how I do ?

2

There are 2 answers

3
rocky On BEST ANSWER

I think the link in the comment ('module' object has no attribute 'Serial') –is relevant. So instead of import nmap, try from nmap import PortScanner and then nm = PortScanner

The fact that you are calling your program nmap.py may in the future cause conflicts, so you may want to rename that.

1
Erkut Emre Uyumaz On

You should uninastall all pip after that install zenmap for windows and pip install comand after you have to restart your pc