content of the file -
print "Go"
used chmod +x devansh.py
to make executable the file
output:
*Error: no such file "Go"*
The file does run but error is always displayed in the output just like above.
content of the file -
print "Go"
used chmod +x devansh.py
to make executable the file
output:
*Error: no such file "Go"*
The file does run but error is always displayed in the output just like above.
Clearly the file devansh.py
lacks a shebang line
that indicates how the script should be executed.
See Why does Python in Linux require the line #!/usr/bin/python? for an
explanation of a shebang line.
Content of devansh.py
:
print "Go"
Attempt to execute it:
chmod +x devansh.py
./devansh.py
Error: no such file "Go"
Content of devansh.py
:
#!/usr/bin/env python
print "Go"
Execute it:
chmod +x devansh.py
./devansh.py
Go
Your question contains three different instances of bad Python usage.
print "Go"
as a bash command. chmod +x devansh.py
. I highlighted these three things in bold text so that you can easily find them.
You got the following error message:
Error: no such file "Go".
...because you're trying to run print "Go"
directly from the terminal as a bash command instead of running it as Python 2.x code which is what it is.
To show the correct path to devansh.py drag the devansh.py file into the terminal. Then change directories using cd
to the directory containing devansh.py and run the command to make devansh.py executable: chmod +x devansh.py
again.
In order for the print "Go"
code to execute successfully Python 2.x needs to be installed.
sudo apt install python2.7
Then execute the devansh.py file by running the following command:
python devansh.py
devansh.py doesn't need to have executable permissions. python devansh.py
will run successfully even if devansh.py is not made executable.
Alternatively you don't need to install python2.7 if you change the print "Go"
code to be compatible with Python 3 which is installed by default.
print("Go")
You don't need to have a file named devansh.py to run this code. Just type python
to start the python interpreter. When the python interpreter is started the prompt changes to >>>
. Then you can run the code directly in the terminal by typing print "Go"
after the python prompt.