Home > Software engineering >  VS Code is not recognizing 'nmap'
VS Code is not recognizing 'nmap'

Time:10-04

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:\Users\mjame\OneDrive\Documents\Jim\Coding\fcc_python_for-pen_testing\nmap_scanner_1> python3 scanner.py
Traceback (most recent call last):
  File "C:\Users\mjame\OneDrive\Documents\Jim\Coding\fcc_python_for-pen_testing\nmap_scanner_1\scanner.py", line 2, in <module>
    import nmap
ModuleNotFoundError: No module named 'nmap'
PS C:\Users\mjame\OneDrive\Documents\Jim\Coding\fcc_python_for-pen_testing\nmap_scanner_1>

I have so far:

  1. Updated to the current Python 3.10.7
  2. Installed Nmap the first time from https://nmap.org/ for Windows
  3. Uninstalled Nmap
  4. Reinsalled Nmap using >>>pip3 install python-nmap

CodePudding user response:

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 be C:\Users\YourLogin\AppData\Local\Programs\Python\Python310\Lib\site-packages.

CodePudding user response:

For future searchers (as in my comment above), if you installed a module with pip3 but are still getting module import errors, try python3 -m pip install <module-name>.

Not sure how/why this happens (pip3 installing somewhere that python3 is not looking for modules), but the above can [usually] help.

  • Related