【问题标题】:Why is 'python' not recognized in powershell?为什么在 powershell 中无法识别“python”?
【发布时间】:2018-05-28 02:18:26
【问题描述】:

我已在我的 Windows 10 PC 中安装了 python 3.6。我也使用 Pycharm 来制作我的脚本。它在那里运行得很好。但我的问题是我无法在 powershell 中运行 python。我被告知只需在 powershell 中键入“python”,它应该会自动启动 python。但是,我收到一条错误消息,说它未被识别。

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\Users\lenovo> python
python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ python
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (python:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

有人建议输入这个:

[Environment]::SetEnvironmentVariable("Path", "$enc:Path;C:\Users\lenovo\AppData\Local\Programs\Python\Python36") 

上面代码中给出的路径对我的电脑是正确的。事实上,Python 在我给出上述代码后运行。但是,这是我的问题。每次我再次关闭并打开 powershell 时,我都必须输入上面的代码才能运行 python。我也尝试在以管理员身份运行的 Powershell 中输入此内容。但是,它不起作用。我什至尝试重新启动我的电脑,但问题仍然无法解决。

每次我想在新的 powershell 窗口中运行 python 时,我都需要输入上面的代码。这有点烦人。任何帮助,将不胜感激。谢谢。

【问题讨论】:

标签: python windows powershell


【解决方案1】:

或者只需在 PowerShell 中输入“py”而不是“python”,然后按 Enter。

【讨论】:

    【解决方案2】:

    您需要将路径添加到您的环境变量中:

    控制面板>系统和安全>系统>高级系统设置>环境变量

    选择编辑路径并追加

    C:\Users\lenovo\AppData\Local\Programs\Python\Python36

    到路径。点击应用并确定。关闭并重新打开 shell 后,您应该能够键入“python”并进入 python shell。

    【讨论】:

      猜你喜欢
      • 2017-11-26
      • 2015-08-23
      • 1970-01-01
      • 2019-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多