Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我以前用shebang
#!/usr/bin/env python
什么时候使用比较好
#!/usr/bin/python
它们之间的确切区别是什么?
#!/usr/bin/python被硬编码为始终运行/usr/bin/python,而#!/usr/bin/env python将运行python您当前环境中的默认值(例如,它会考虑到$PATH,您可以检查将使用哪个 python 解释器which python)。
/usr/bin/python
python
$PATH
which python
第二种方式 ( #!/usr/bin/env python) 是首选,因为它不依赖于特定的安装。例如,它将适用于virtualenv没有 的设置或系统/usr/bin/python,但只有例如/usr/local/bin/python。
virtualenv
/usr/local/bin/python