Ubuntu Python shebang line not working
If you are trying to run the command as
$ test.py
the error may not have anything to do with the shebang. Rather, the directory that test.py resides in is not in your PATH
. Try
$ ./test.py
to bypass PATH
lookup.
(This is in addition to making sure that the script itself is executable.)
Python - what is the shebang line supposed to do if the stated version is not installed ?? what if shebang is not the first line?
The shebang is what will be run if the script is run with chmod +x test.py
and then ./test.py
. Then the shell (i.e. bash) will run /usr/bin/env python2 test.py
. However, when you explicitly use python3 test.py
the shell will not check your shebang, it will just run python3
.
Also, if you put the shebang at any line other than the first, it is no longer a shebang. Quoting Wikipedia:
In computing, a shebang is the character sequence consisting of the characters number sign and exclamation mark (#!) at the beginning of a script.
The shsebang can only be at the biginning. If it is not then the shell will not look at it, so it ran test.py
as a shell script, where many commands are not found.
shebang line not working
Your file has Windows-type line endings. Convert it to proper Unix-type line endings and you should be good to go.
$ dos2unix test.py
Related Topics
Bash Completion for Path in Argument (With Equals Sign Present)
How Does One Determine the Page Frame Number for Device Memory
Low-Overhead Way to Access the Memory Space of a Traced Process
Setting Per-File Flags with Automake
Gdb Warning: Loadable Section Not Found in Added Symbol-File System-Supplied Dso at 0X7Ffff7Ffd000
Debugging Shared Libraries Remotely with Gdb/Gdbserver
How to Avoid the Prompts While Using Azcopy on Linux in a Script
Bash Not Trapping Interrupts During Rsync/Subshell Exec Statements
Xkb: How to Convert a Keycode to Keysym
How to Access the Base Filename of a File You Are Sourcing in Bash
.Bashrc Syntax Error: Unexpected End of File
Direct Control of Hci Device (Bypass Bluetooth Drivers) on Linux
Linux, Gnu Gcc, Ld, Version Scripts and the Elf Binary Format -- How Does It Work
Installing Multiple Versions of R
Qt Version Is Not Properly Installed, Please Run Make Install