I am trying to make a nmap scanner for the InfoSec Certification on freeCodeCamp.org and cannot get Visual Studio Code to recognize that I have installed nmap. I am very beginner and in the process of learning.
from cProfile import run
import nmap
scanner = nmap.PortScanner()
print("Welcome, this is a simple automattion tool")
print("<------------------------------------------->")
When I run this in VS Code I get the following in the terminal:
PS C:UsersmjameOneDriveDocumentsJimCodingfcc_python_for-pen_testingnmap_scanner_1> python3 scanner.py
Traceback (most recent call last):
File "C:UsersmjameOneDriveDocumentsJimCodingfcc_python_for-pen_testingnmap_scanner_1scanner.py", line 2, in <module>
import nmap
ModuleNotFoundError: No module named 'nmap'
PS C:UsersmjameOneDriveDocumentsJimCodingfcc_python_for-pen_testingnmap_scanner_1>
I have so far:
- Updated to the current Python 3.10.7
- Installed Nmap the first time from https://nmap.org/ for Windows
- Uninstalled Nmap
- Reinsalled Nmap using
>>>pip3 install python-nmap
2
Answers
It seems that Python cannot find
nmap
module.You can either add it to path in Windows via Start -> Edit system environment variables -> Environment variables… and then edit
PATH VARIABLE
by adding at the end path to nmap module that you have installed or move the module to default Python modules directory which should beC:UsersYourLoginAppDataLocalProgramsPythonPython310Libsite-packages
For future searchers (as in my comment above), if you installed a module with
pip3
but are still getting module import errors, trypython3 -m pip install <module-name>
.Not sure how/why this happens (
pip3
installing somewhere thatpython3
is not looking for modules – maybePYTHONPATH
-related), but the above can [usually] help.