【问题标题】:Can't run python program from command prompt even though python 3.9 is installed [duplicate]即使安装了python 3.9,也无法从命令提示符运行python程序[重复]
【发布时间】:2021-10-26 10:30:15
【问题描述】:

Command prompt

我试图运行这个 python 代码:

#two brown number are an ordered pair in the form (m; n) such that n!+1=m^2
from math import factorial as fact
m=2
n=2
for i in range(10**2): # range of values to check
    # checks current values and changes them according to results
    if (fact(n)+1)==m**2:
        print(m,n)
        m+=1
        n+=1
    elif (fact(n)+1)<m**2:
        n+=1
    elif (fact(n)+1)>m**2:
        m+=1

从命令提示符,但它向我显示了上图中的消息,即使我已经从官方网站安装了 python 3.9。

The python stuff I installed

有人知道如何解决这个问题,还是我必须从 Microsoft Store 重新安装 python?

【问题讨论】:

标签: python windows-10 command-prompt python-3.9


【解决方案1】:

重命名包含代码的文件。 不能有空格,然后使用命令:

python3 filename.py

【讨论】:

    【解决方案2】:

    要调用带有空格的文件,请在它们周围使用引号。 python ".\brown numbers.py"

    通常,文件名中最好避免使用空格,但有时这是不可避免的。在这种情况下,您必须明确告诉 Python 什么是完整文件名。

    要检查 Python 是否安装正确,请运行: python --version

    【讨论】:

      猜你喜欢
      • 2021-09-21
      • 1970-01-01
      • 2019-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多