[英]Python runs in Powershell but not command prompt
I am using Windows 7 and have Python 2.7 installed in C:\\Python27a
. 我正在使用Windows 7,并在
C:\\Python27a
安装了Python 2.7 。 This location has been added to my Path system variable
. 此位置已添加到我的
Path system variable
。 When I use the command prompt, typing python
returns the error message python' is not recognized...
However using Powershell I can type in python
and it starts as expected. 当我使用命令提示符时,键入
python
返回错误消息python' is not recognized...
但是,使用Powershell可以键入python
并且它按预期启动。
I have had another user confirm that the Path variable is correct by installing Python on his machine, adding the location to Path, and running from the command prompt in the exact same fashion that I attempted. 我有另一个用户通过在他的机器上安装Python,将位置添加到Path并以与我尝试的完全相同的方式从命令提示符运行来确认Path变量正确。 I am lead to believe that at some point (which I can't remember) I foolishly changed a setting in Powershell that makes it access the
Path
whereas CMD
no longer can. 我被认为是在某个时候(我不记得了),我愚蠢地更改了Powershell中的设置,使它可以访问
Path
而CMD
不再可以访问。
This is my Path variable (the python location is at the end): 这是我的Path变量(python位置位于末尾):
C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\MKS Toolkit\mksnt;C:\PROGRA~2\MKSTOO~1\bin64;C:\PROGRA~2\MKSTOO~1\bin;C:\PROGRA~2\MKSTOO~1\bin\X11;C:\PROGRA~2\MKSTOO~1\mksnt;C:\IBM\InformationServer/jdk32\jre\bin;C:\IBM\InformationServer/jdk32\jre\bin\j9vm;C:\IBM\InformationServer\ASBNode\lib\cpp;C:\IBM\InformationServer\ASBNode\apps\proxy\cpp\vc60\MT_dll\bin;C:\Program Files\Common Files\Microsoft Shared\Microsoft Online Services;C:\Program Files (x86)\Common Files\Microsoft Shared\Microsoft Online Services;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn";C:\Python27a
This is not a serious problem, as I can still run Python by manually changing to the directory C:\\Python27
before entering python
or I can always just use IDLE , but I am curious why this is happening and how it can be resolved? 这不是一个严重的问题,因为我仍然可以通过在输入
python
之前手动更改为目录C:\\Python27
来运行Python,或者我始终可以仅使用IDLE ,但我很好奇为什么会这样以及如何解决?
RESOLVED: I fixed this by placing "C:\\Python27a" earlier in the the Path variable. 解决:我通过在路径变量中放置“ C:\\ Python27a”来解决此问题。 The multiple occurrences of %SystemRoot% seemed suspicious to me, so I wanted to read the python location first and sure enough, it now works.
%SystemRoot%的多次出现对我来说似乎是可疑的,所以我想先阅读python位置,然后确定,现在可以了。 I don't know yet what the underlying cause of the problem was, but I will report back when I find out.
我还不知道问题的根本原因是什么,但是当我发现问题时,我会报告。
If the path variable you provided indeed is accurate, then you seem to have a stray double-quote (") in there that can mess things up: ...\\Binn";C:\\Python27a 如果您提供的路径变量确实是正确的,那么您似乎在其中包含了一个可能引起混乱的双引号(“):... \\ Binn”; C:\\ Python27a
Try removing that double quote character. 尝试删除该双引号字符。
Add a trailing backslash at the end of the path so that it is 在路径的末尾添加一个反斜杠,以便
C:\\Python27a\\
C:\\ Python27a \\
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.