简体   繁体   English

为什么 Windows 看不到 python.exe?

[英]Why does Windows not see python.exe?

Update 3: Found it - it's a "helpful" feature of Windows to go find apps via the Windows store ( details here ).更新 3:找到它 - 这是 Windows 的一项“有用”功能,可以通过 Windows 商店查找应用程序( 详情请点击此处)。

I installed Anaconda (following a Udacity course) and am trying to get it set up right to run on Windows.我安装了 Anaconda(遵循 Udacity 课程),并试图将其设置正确以在 Windows 上运行。 The Udacity course assumes I have Git Bash (I don't) and so it's not much help. Udacity 课程假设我有 Git Bash(我没有),所以它没有多大帮助。

I added the following to the path:我在路径中添加了以下内容:

  • C:\\Users\\david\\anaconda3 C:\\用户\\大卫\\anaconda3
  • C:\\Users\\david\\anaconda3\\Scripts C:\\Users\\david\\anaconda3\\Scripts

When I run "conda --version" I get the expected version number.当我运行“conda --version”时,我得到了预期的版本号。 But when I run "python --version" I get:但是当我运行“python --version”时,我得到:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional>python --version
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional>

When I run "path", it is there:当我运行“路径”时,它在那里:

... 
Studio\bin;C:\Users\david\.dotnet\tools;C:\Users\david\AppData\Local\GitHubDesktop\bin;C:\Users\david\anaconda3;C:\Users\david\anaconda3\Scripts;C:\Program Files\JetBrains\PyCharm 2021.1.2\bin;;;C:\Program Files (x86)\Microsoft Visual St
...

And explicitly setting the location of python.exe works:并显式设置 python.exe 的位置有效:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional>\users\david\anaconda3\python --version
Python 3.8.8

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional>

So why does it not find it when I just run python?那么为什么我只运行python时找不到它呢?

Update: Yes I opened a new command window after saving the additions to the path (always a good question to ask though).更新:是的,我在将添加的内容保存到路径后打开了一个新的命令窗口(尽管总是一个好问题)。

For running where:用于运行:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional>where python
C:\Users\david\AppData\Local\Microsoft\WindowsApps\python.exe
C:\Users\david\anaconda3\python.exe

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional>

So it finds it under where, but not when trying to run it.所以它在 where 下找到它,但在尝试运行它时找不到。

Update 2: Is it possible that Windows does not want to run apps under the c:\\users folder for security reasons?更新 2:出于安全原因,Windows 是否可能不想在 c:\\users 文件夹下运行应用程序? It's an unusualy place to put a .exe.这是一个放置 .exe 的不同寻常的地方。

This is mostly a guess since you haven't provided the full value of your PATH variable, but I think the entry for your Anaconda folder occurs after the entry for <user>\\AppData\\Local\\Microsoft\\WindowsApps\\python.exe so it gets hidden.这主要是猜测,因为您没有提供 PATH 变量的完整值,但我认为您的 Anaconda 文件夹的条目出现在<user>\\AppData\\Local\\Microsoft\\WindowsApps\\python.exe的条目之后,所以它被隐藏。

Windows searches the folders in PATH in order and executes the first python.exe file that it finds, which in this case is the message saying to download Python from the Store. Windows 按顺序搜索 PATH 中的文件夹并执行它找到的第一个python.exe文件,在这种情况下,该文件是说从应用商店下载 Python 的消息。

Try making \\users\\david\\anaconda3\\ as the first value in your PATH value.尝试将\\users\\david\\anaconda3\\作为 PATH 值中的第一个值。

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

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