【问题标题】:Run a python script in terminal在终端中运行 python 脚本
【发布时间】:2016-02-11 15:27:45
【问题描述】:

我正在尝试在终端 hello.py python 脚本中运行:

#! usr/bin/env python3  
print("Hello", "World!")

在终端中调用以下内容(在 hello.py 所在的工作目录中):

$ chmod +x hello.py
$ ./hello.py

我得到:

bash: ./hello.py: usr/bin/env: bad interpreter: No such file or directory

我无法超越它。我在终端中检查了以下内容 (可能需要进一步澄清):

_____________________________________________________________________
$ python3
Python 3.4.2 (default, Oct  8 2014, 10:45:20) 
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.executable)
/usr/bin/python3
_____________________________________________________________________
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
_____________________________________________________________________
$ which python3
/usr/bin/python3
_____________________________________________________________________

感谢您的澄清!

【问题讨论】:

  • Debian 建议使用解释器的绝对路径,例如 /usr/bin/python3

标签: python linux debian interpreter


【解决方案1】:

很简单,你忘了给出绝对路径。

使用 #!/usr/bin/env python3

【讨论】:

  • 这并不完全清楚。我认为你应该说,“你忘了包括第一个斜线。”乍一看,这和他尝试过的一样。
猜你喜欢
  • 2020-05-27
  • 1970-01-01
  • 2017-06-14
  • 2012-07-07
  • 2020-04-01
  • 2018-01-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多