Reputation:
I want to put the path to the python file first in the file to run it without having to type python before it. Here is the output of the terminal that comfiuses me
[Wolfie@Wolfies-MacBook-Pro] [08:54:28] [/Applications/MAMP/cgi-bin]
$python test.py
blaaaaa
[Wolfie@Wolfies-MacBook-Pro] [08:54:32] [/Applications/MAMP/cgi-bin]
$which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
[Wolfie@Wolfies-MacBook-Pro] [08:54:39] [/Applications/MAMP/cgi-bin]
$cat test.py
#!/Library/Frameworks/Python.framework/Versions/2.7/bin/python
print "blaaaaa"
[Wolfie@Wolfies-MacBook-Pro] [08:54:45] [/Applications/MAMP/cgi-bin]
$ls -l test.py
-rwxr-xr-x 1 Wolfie admin 83 Oct 14 08:53 test.py
[Wolfie@Wolfies-MacBook-Pro] [08:54:49] [/Applications/MAMP/cgi-bin]
$./test.py
: No such file or directoryry/Frameworks/Python.framework/Versions/2.7/bin/python
./test.py: line 2: print: command not found
On Ubuntu, Debian and Red Hat this way works. I also tried with "/usr/bin/python" and "/usr/local/bin/python3" which work when I put it before the filename in the terminal and run it but not when I put it first in the file then chmod +x it.
Upvotes: 0
Views: 287
Reputation: 113
With any programming language, I'll use #!/usr/bin/env [language]
and in this case replace [language]
with python
.
Upvotes: 1