在终端中运行python脚本而不使用python命令

问题描述:

我有一个python脚本让我们把它命名为script1.py。我可以在终端以这种方式运行它:

I have a python script let's name it script1.py. I can run it in the terminal this way:

python /path/script1.py
...

但我想像命令行程序运行:

but I want to run like a command-line program:

arbitraryname
...

您使用 shebang line

#!/usr/bin/env python

使文件可执行:

chmod +x arbitraryname

PATH上的目录(可以是符号链接):

and put it in a directory on your PATH (can be a symlink):

cd ~/bin/
ln -s ~/some/path/to/myscript/arbitraryname