[Python] cmd中‘py‘命令不被识别的解决方案

[Python] cmd中'py'命令不被识别的解决方案

        • 附:环境变量设置方法

最近我的兴趣从Python转移到了C语言,在给MinGW-W64添加环境变量(Path)的时候,不小心覆写了Python的Path。

重新添加回来之后,发现原来一直在用的py命令竟然不能用了:

平时我都是使用

py demo.py

现在会报错:

‘py’ is not recognized as an internal or external command, operable program or batch file.

但是把上面的命令中的py换成python命令就没有问题,实在是令人大惑不解。

经过一晚上的研究,总算发现,py命令是靠调用以下文件来实现的:

C:\Windows\py.exe

所以解决方法很简单,把C:\Windows也加到环境变量里面就Ok了。

附:环境变量设置方法
  1. 打开系统标签:Control+Pause/Break
  2. 点击左侧的高级系统设置
  3. 点击环境变量
  4. 找到Path,点击编辑
  5. 如果里面已经存在其它的环境变量,可以在其后添加字符;来分隔
  6. 可以参考我的Path:

C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Users\luwieer\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\luwieer\AppData\Local\Programs\Python\Python38\Scripts;C:\Users\luwieer\AppData\Local\Programs\Python\Python38;C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin;C:\Windows

  1. 完成添加后,如果有打开的cmd窗口,请关闭后重新开启。在cmd中输入py,熟悉的界面就又回来了:

C:\Users\luwieer>py
Python 3.8.6 (tags/v3.8.6:db45529, Sep 23 2020, 15:52:53) [MSC v.1927 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>>

你可能感兴趣的:(python,cmd,windows)