How can I run a python script in Terminal on Mac without using the "python" keyword, without having to edit my existing python files?
Right now I have to do this:
python script.py
What I like to do is this:
script.py
Add a shebang:
#!/usr/bin/python
or
#!/usr/bin/env python
I prefer the second one, since Python can be anywhere like /usr/bin/python, /usr/local/bin/python etc. and second one ensure that you don't have to keep editing the shebang.
And then you can just execute it as ./script.py if it is executable.
in your python script add this as your first line
#!/usr/bin/python
then in terminal do this chmod +x ./yourpythonscript.py
then from terminal execute as ./yourpythonscript.py
#! /usr/bin/env python is marginally more portable as it doesn't hardcode where python is.Try ./script.py instead of script.py ... or ensure your current directory is in your path and script.py should work....
command not found.