It is a tough problem. There are several topics for it. But none of them helps me.
I added #!/usr/bin/env python3
(or python), and run test.py
, it reported that zsh: command not found: test.py
. I was confused. I had tried many forms of shebang. Can you help me?
In following error reports, you can see that the reports are different when running it under HOME path and under the parent path of test.py
[Scripts] test.py 20:51:04
zsh: command not found: test.py
[Scripts] cd ~ 20:51:33
[~] Scripts/test.py 20:51:43
env: python\r: No such file or directory
It's not so long since I got the meaning of the shebang line. I hope that it can make my life easy, never writing python
before test.py
.
Following is the test code.
#!/usr/bin/env python3
import argparse
parser = argparse.ArgumentParser(description='test')
parser.add_argument('-o', dest='what', action='store', default='hello', metavar='WHAT')
args = parser.parse_args()
print(args.what)
Following is the configuration.
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:$PATH"
And in terminal,
[~] which python 20:36:55
python: aliased to python3
[~] which python3 20:36:57
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
ls -l
-rwxrwxrwx@ 1 william staff 273 10 24 20:51 test.py