在PowerShell中无法识别Python 3.6

Gau*_*m J 4 python windows powershell

我在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
Run Code Online (Sandbox Code Playgroud)

有人建议输入:

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

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

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

小智 8

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

查看该图像以查看其工作原理。


cos*_*iry 7

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

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

选择编辑PATH并追加:

C:\用户\联想\应用程序数据\本地\程序\ Python的\ Python36

到了路上.点击申请即可.关闭并重新打开shell之后,你应该可以输入"python"并进入python shell.