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
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
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.
Try./script.py instead of script.py... or ensure your current directory is in your path and script.py should work....
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.