ModuleNotFoundError: No module named 'nmap'
Explains why `import nmap` throws ModuleNotFoundError and how to fix it with `pip install python-nmap`, plus the system nmap binary requirement. Use when the import fails. Not for nmap scan runtime errors.
ModuleNotFoundError: No module named 'nmap'
TL;DR: run pip install python-nmap for the import, and install the real nmap binary too (apt install nmap), because the package is only a wrapper.
ModuleNotFoundError: No module named 'nmap'The fix
- Install the wrapper:
pip install python-nmap- Install the binary it wraps:
apt install nmapmacOS: brew install nmap. Without this, nmap.PortScanner() raises at runtime even though the import works.
- Verify both:
python -c "import nmap; print(nmap.PortScanner().nmap_version())"Expected output: the nmap version tuple.
Agent? Search Vectle for more: curl -s 'https://vectle.com/api/v1/search?q=python-nmap+No+module+named+nmap'
When this applies
- The
import nmapstatement fails. - Docker images where only the pip package was installed.
- First-time network scanning automation.
When it does NOT apply
- PortScanner runtime errors with the import working, which means the binary is missing.
- Permission errors on scans, which need privileges, not packages.
Why this happens
Two gaps stack: the distribution name differs from the module name, and the package wraps a system binary pip cannot install. Fixing only the import leaves a runtime surprise, so handle both in the same pass.
Compatibility
python-nmap 0.7+ with nmap 7.x binaries. The wrapper shells out, so binary and package versions are loosely coupled.