Zero Days Zero Days - 1 year ago 91
Python Question

('Nmap not found', <class 'nmap.nmap.PortScannerError'>)

Where is the problem?

import nmap

I installed nmap and python, and when I use
import nmap
there is no any problem. But when use:


this error is thrown:

Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
File "./nmap/", line 153, in __init__
raise PortScannerError('nmap program was not found in path. PATH is:{0}'.format(os.getenv('PATH')))
nmap.nmap.PortScannerError: 'nmap program was not found in path. PATH is : /usr/lib /lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games: /usr/local/games'"

Answer Source

python-nmap seems to depend on nmap, which is the binary that does the actual network scanning and auditing.

You can check in a terminal if nmap is in your $PATH with the following command:

 which nmap


You can install nmap in debian-like distros with:

apt-get install nmap

Arch linux:

pacman -Sy nmap

Already installed nmap

If you're sure the nmap binary is installed, but you think it is not in your $PATH, you might have to add the directory where nmap is installed to your $PATH.

To do that, edit the .bashrc file in your user's directory, or /etc/bashrc (which will change for all users) and add the following:

export PATH="$PATH:/usr/local/nmap/bin"

but changing /usr/local/nmap/bin for the directory where the nmap binary is installed. After changing the file, be sure to open a new shell session, or type exec bash to refresh it.

You also have to make sure, that it has execute permission (chmod +x <file>).

When you execute:

nmap --version

You should see something like this:

Nmap version 6.46 ( )
Platform: i686-pc-linux-gnu
Compiled with: liblua-5.2.3 openssl-1.0.1g libpcre-8.34 libpcap-1.5.3 nmap-libdnet-1.12 ipv6
Compiled without:
Available nsock engines: epoll poll select

If you do, nmap is installed and in your $PATH.