Error import nmap into python

Question:

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 ?

Asked By: davy

||

Answers:

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.

Answered By: rocky

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

Answered By: Erkut Emre Uyumaz
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.