pythonpython-3.xpathnmap

Python nmap program was not found in path error even nmap installed and nmap.exe is in the path


For some reason I can't use nmap on python. I have python-nmap installed as a library. Whenever I try to use PortScanner(), I get path error but I have nmap installed on my computer and it is even in path.

import nmap

nm = nmap.PortScanner()

print(nm)

The error is

raise PortScannerError(
nmap.nmap.PortScannerError: 'nmap program was not found in path. PATH is : C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\nodejs\\;C:\\Program Files\\dotnet\\;C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\170\\Tools\\Binn\\;C:\\Program Files (x86)\\dotnet\\;C:\\Users\\Anti\\AppData\\Local\\Programs\\Python\\Python38\\Scripts\\;C:\\Users\\Anti\\AppData\\Local\\Programs\\Python\\Python38\\;C:\\Program Files\\Java\\jdk-13.0.2\\bin;C:\\Users\\Anti\\Desktop\\Selenium;C:\\Users\\Anti\\Desktop\\C++;C:\\ffmpeg\\bin;;C:\\Users\\Anti\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\MinGW\\bin;C:\\Users\\Anti\\AppData\\Roaming\\npm;C:\\Users\\Anti\\.dotnet\\tools;C:\\Program Files (x86)\\Nmap'

My nmap files are in the path as you can see.

C:\\Program Files (x86)\\Nmap

I tried to reinstall nmap and add in path again, nothing changed. I can use the nmap command directly on cmd without any problems. By the way, I don't use virtualenv. How can I solve this?


Solution

  • I know this is old thread. But if someone is searching for similar answer.
    What @sushanth answered is correct. It just has to be list:

    nmap_path = [r"C:\Program Files (x86)\Nmap\nmap.exe",]
    scanner = nmap.PortScanner(nmap_search_path=nmap_path)