1

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

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I agree. But at first while i was sharing, moderator suggested. So i changed it. I changed name and instead of import nmap , wrote from nmap import nmap. But it doesn't work.
Did you try renaming the file too?
Make sure you get rid of the old nmap.pyc or cache file if that's there. If that doesn't do it break out a debugger. I have a good one called trepan2. You should be able to step into the import statement.
-1

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

1 Comment

This wont fix the issue as it's the way in which it is imported that is the issue, not a missing module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.