简体   繁体   English

Python 可执行文件在 Windows 上无法识别 10

[英]The Python executable is not recognized on Windows 10

I recently installed Python 3.6.3 on my device.我最近在我的设备上安装了 Python 3.6.3。 When I type python in my cmd window, it gives me this error.当我在我的cmd window 中键入python时,它给了我这个错误。 I do have the PATH in the environment variables.我在环境变量中确实有 PATH。 Path Lists .路径列表 This should normally fix it, but python is still not recognized.这通常应该修复它,但仍然无法识别python

Make sure the path is in your System PATH variable and not in a User PATH variable.确保路径在您的系统 PATH 变量中,而不是在用户 PATH 变量中。 After adding the path to the PATH variable, make sure you close and re-open any command prompts so they use the updated PATH.将路径添加到 PATH 变量后,请确保关闭并重新打开所有命令提示符,以便它们使用更新的 PATH。

You should also confirm the path by checking python directly from the folder.您还应该通过直接从文件夹中检查 python 来确认路径。

The example below is for the OP's path.下面的示例适用于 OP 的路径。

Make sure you use the path specific to your installation:确保使用特定于安装的路径:

  1. %USERPROFILE%\\AppData\\Local\\Programs\\Python\\Python36 %USERPROFILE%\\AppData\\Local\\Programs\\Python\\Python36

  2. %USERPROFILE%\\AppData\\Local\\Programs\\Python\\Python36\\Scripts for access to tools such as PIP %USERPROFILE%\\AppData\\Local\\Programs\\Python\\Python36\\Scripts for access to tools such as PIP

  3. %USERPROFILE%\\AppData\\Local\\Programs\\Python\\Launcher %USERPROFILE%\\AppData\\Local\\Programs\\Python\\Launcher

    cd c:\\Python\\Python36-32 cd c:\\Python\\Python36-32

    python --version蟒蛇--版本

or using CMD or Powershell on Windows: \\>Python --version should print Python 3.xx where x = version specific numbers.或在 Windows 上使用 CMD 或 Powershell: \\>Python --version应打印Python 3.xx ,其中 x = 版本特定数字。

I had the same problem, due to a stupid decision from Microsoft.由于微软的一个愚蠢决定,我遇到了同样的问题。

I had another line in my system path variable: C:\\Users\\MyUserName\\AppData\\Local\\Microsoft\\WindowsApps我的系统路径变量中有另一行: C:\\Users\\MyUserName\\AppData\\Local\\Microsoft\\WindowsApps

And windows 10 put there a python.exe file that only redirected me to the python page of the Microsoft Store: Windows 10 在那里放了一个python.exe文件,它只将我重定向到 Microsoft Store 的 python 页面: 在此处输入图片说明

Since this line was above my true python path, typing python in the cmd prompt opened the Microsoft Store... This... is... 100% a stupid decision.由于这一行在我真正的 python 路径之上,因此在 cmd 提示符下键入python打开 Microsoft Store ......这......是...... 100% 一个愚蠢的决定。

Solution:解决方案:

Type App execution aliases in the windows 10 search bar, then uncheck the aliases for python.exe and python3.exe .在 Windows 10 搜索栏中键入App execution aliases ,然后取消选中python.exepython3.exe的别名。 More information here更多信息在这里

If still not working, as mentioned above in the answers, then simply move up the path, as shown in the screenshot.如果仍然无法正常工作,如上述答案中所述,则只需向上移动路径,如屏幕截图所示。

图像在这里

All the answers on StackOverflow about it were obsolete so decided to add this. StackOverflow 上关于它的所有答案都已过时,因此决定添加此内容。 The path variable that needs to be added is,需要添加的路径变量是,

C:\Users\Username\AppData\Local\Programs\Python\Python36-32

Note that everyone may have a different Username.请注意,每个人可能有不同的用户名。

you get this error because the python.exe path has not been added to the System environment variable to do that simply您收到此错误是因为尚未将python.exe路径添加到系统环境变量中以简单地执行此操作

  1. go to the path C:\\Users\\%Username%\\AppData\\Local\\Programs\\Python\\Python37-32 which contains python.exe转到包含python.exe的路径C:\\Users\\%Username%\\AppData\\Local\\Programs\\Python\\Python37-32

  2. copy the path and open system environment variables and in the variable section look for variable called Path if not create new variable with Variable Name as Path and value as the copied path复制路径并打开系统环境变量,并在变量部分查找名为 Path 的变量,如果没有创建新变量,变量名作为路径,值作为复制的路径

在此处输入图片说明

  1. once you do that close the window and simply open cmd and type python you should get something like this一旦你关闭窗口并简单地打开 cmd 并输入 python 你应该得到这样的东西

在此处输入图片说明

If you are working with command prompt and if you are facing the issue even after adding python path to system variable PATH.如果您正在使用命令提示符,并且即使在将 python 路径添加到系统变量 PATH 后仍面临此问题。

Remember to restart the command prompt (cmde.exe).请记住重新启动命令提示符 (cmde.exe)。

If you are trying to install new python version python-3.9.6 then click the checkbox of Add Python 3.9 to PATH如果您尝试安装新的 Python 版本python-3.9.6请单击Add Python 3.9 to PATH复选框

在此处输入图片说明

For Python 3.6 there are actually 2 path entries.对于 Python 3.6,实际上有 2 个路径条目。 Also it's best to use the %USERPROFILE% rather then hard coding it.此外,最好使用 %USERPROFILE% 而不是硬编码。

%USERPROFILE%\\AppData\\Local\\Programs\\Python\\Python36 %USERPROFILE%\\AppData\\Local\\Programs\\Python\\Python36\\Scripts %USERPROFILE%\\AppData\\Local\\Programs\\Python\\Python36 %USERPROFILE%\\AppData\\Local\\Programs\\Python\\Python36\\Scripts

Just Set The Path Variable Correctly As Follows- Go To The Properties Of ThisPc Click Advanced System Settings Click Environment Variables... In System Variables Edit The Path Variable To只需按如下方式正确设置路径变量-转到ThisPc的属性单击高级系统设置单击环境变量...在系统变量中将路径变量编辑为

C:\\Users\\Username\\AppData\\Local\\Programs\\Python\\Python36-32 C:\\Users\\Username\\AppData\\Local\\Programs\\Python\\Python36-32

Note That, Everyone May have Different UserName.请注意,每个人可能有不同的用户名。

I too was struggling with this issue, and everything was configured correctly.我也在为这个问题苦苦挣扎,一切都配置正确。 I installed and setup my system path variables as one would.我安装并设置了我的系统路径变量。 And everything was fine.一切都很好。 Then upon reboot windows would not recognize 'python' as a command as if it were unaware of the path variable.然后在重新启动时,Windows 不会将“python”识别为命令,就好像它不知道路径变量一样。 Double checked to confirm everything was still setup correctly (it was).仔细检查以确认一切仍然正确设置(确实如此)。

It only started to work again after I manually browsed to the directory in which python.exe existed, and ran 'python'.在我手动浏览到存在 python.exe 的目录并运行“python”后,它才再次开始工作。 After that windows seemed to recognize my path variable and I could call 'python' from where ever need be.在那之后,windows 似乎识别了我的路径变量,我可以从任何需要的地方调用“python”。 Very odd.很奇怪。 Figured I'd share in case someone else runs into this.想我会分享以防其他人遇到这个问题。

This happens because the path doesn't exist in environment variables.发生这种情况是因为该路径不存在于环境变量中。 To fix this :要解决这个问题:

  1. Re-run the installer重新运行安装程序
  2. Choose Modify选择修改
  3. In optional feature click "Next"在可选功能中单击“下一步”
  4. In advanced option tick the "Add Python to environment variables"在高级选项中勾选“将 Python 添加到环境变量”
  5. Install安装

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM