I'm using Ubuntu 12.04 and installed python-nmap to create a script. If I use IDLE and type in the following, it runs fine:
import nmap
nm = nmap.PortScanner()
nm.scan('127.0.0.1', '22-443')
However, if I perform this in Eclipse, I receive the following error:
Traceback (most recent call last):
File "/home/russ/workspace/ViPyNmap/MyFiles/nmaptest.py", line 2, in <module>
nm = nmap.PortScanner()
AttributeError: 'module' object has no attribute 'PortScanner'
I've added the egg file and also the folder to the Eclipse path for the project, with no luck. I've also restarted Eclipse after doing so, with no luck. I apologize for my inexperience with both Eclipse and Python and appreciate the help.
You likely installed the package "nmap", not "python-nmap":
So, just uninstall "nmap" and install "python-nmap":
pip uninstall nmap
pip install python-nmap
Well above answers are working fine in python 2.7, but when we are working in python3 environment following will help to resolve it
pip uninstall nmap pip uninstall python-nmap pip3 install python-nmap
The reason why this is happening is because your module that you named nmap.py is now shadowing the intended requests module you are trying to use.
To avoid this, you should rename your module to something else to avoid these situations. Furthermore, chances are you will have generated a nmap.pyc file as well, local to where your nmap.py resides. Make sure you remove that as well after your rename, as the interpreter will still reference that file, re-producing the error.
Example of problem resolution:
renaming file to nmapscan.py, removing nmap.pyc and running again.
If you see the source code nmap.py
at directory /usr/local/lib/python2.7/dist-packages/nmap/
, you will find that there is not class PortScanner.
You should delete the directory .../nmap/
with contained files, and install the new the packages nmap
or bypython setup.py install
at new packages directory.
You also can copy the file nmap.py
at the new packages to your directory .../MyFiles/
with your py file nmaptest.py
, and run your command python nmaptest.py
.
good luck for you !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With