无法在 Python 3.8.0 的命令行上运行 python 文件;它改为调用 python 解释器

Posted

技术标签:

【中文标题】无法在 Python 3.8.0 的命令行上运行 python 文件;它改为调用 python 解释器【英文标题】:Cannot run python file on command line with Python 3.8.0; it invokes python interpreter instead 【发布时间】:2020-02-28 08:19:20 【问题描述】:

我有一个 python 文件 test.py 当我尝试使用 $ python test.py 在终端中运行它时, 它没有按预期运行,而是调用 python 解释器。

我已经安装了python 3.8.0。

python文件中的代码是:

#!/usr/bin/python 
print("Hello World!")

它应该打印 世界你好!

而是调用 python 解释器:

$ python test.py 
Python 3.8.0 (v3.8.0:fa919fdf25, Oct 14 2019, 10:23:27) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

【问题讨论】:

试试:python3 test.py 【参考方案1】:

检查which python 的输出。 可能是ipython -i 的别名之类的。

【讨论】:

问题中Python的启动信息明确说明了操作系统:[Clang 6.0 (clang-600.0.57)] on darwin

以上是关于无法在 Python 3.8.0 的命令行上运行 python 文件;它改为调用 python 解释器的主要内容,如果未能解决你的问题,请参考以下文章