Running python script from Linux Terminal

It seems you have a badly-written shebang line. From the error you're getting:

-bash: /usr/bin/pyAES.py: /usr/bin/python2: bad interpreter: No such file or directory

I'd say you should set the first line of /usr/bin/pyAES.py to

#!/correct/path/to/python

where the /correct/path/to/python can be found from the output of:

type -P python

It's /usr/bin/python (not /usr/bin/python2) on my system.


The first hurdle is that you need to tell the shell where to find the program. If you don't put any directory indication, you can only run executable files located in the executable search path described by the PATH environment variables. The current directory is not in the search path unless you put it there. So run ./pyAES.py.

In order to run a program, you must have execution permissions on it:

chmod +x pyAES.py

If you get a message like “bad interpreter: No such file or directory” or simply “No such file or directory” on a file that exists, it means that there is an error in the script's shebang line. (See /bin/sh: ./check-dependencies.pl: not found — but check-dependencies.pl exists! for a more detailed explanation.) The shebang line is the first line of the script and indicates the location of the interpreter.

To avoid hard-coding the path to an interpreter (e.g. /usr/bin/python or /usr/local/bin/python), you can use the /usr/bin/env program as a trampoline:

#!/usr/bin/env python

PEP 304 specifies that #!/usr/bin/env python2 is the right away to refer to Python 2.x. However there are plenty of existing systems where Python 2.x is only provided under the name python and not python2. So you may have to juggle between the two. If you have root permissions and your distribution only provides Python 2.x as python or only provides python2, create a symbolic link to the other name.

If you see the error “: No such file or directory” (with nothing before the colon), it means that your shebang line has a carriage return at the end, presumably because it was edited under Windows. Remove the CR: the shebang line needs to have a Unix line ending (linefeed only).


The Error "command not found" you are getting because that executable does not exists in /bin/ or /usr/bin/ all paths in $PATH variable.

When you run any command, in backend shell searches that executable/binary in PATH , eg. /bin/ /usr/bin/ etc...

So if path not properly define then you will face this issue.

and when you use " ./command " then it will execute that command from current direcotry , the PATH variable is not used to search for the file name