无法在powershell上运行python [英] Can't run python on powershell

查看:381
本文介绍了无法在powershell上运行python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 PowerShell 中输入 python 时,出现如下错误:

程序 'python' 执行失败:系统找不到指定的文件在行:1 字符:11+ python.exe <<<<.在行:1 字符:1+ <<<<蟒蛇+ CategoryInfo : ResourceUnavailable: (:) [], ApplicationFailedException+ FullQualifiedErrorId : NativeCommandFailed

我已将 C:\Python27 及其子目录添加到 PATH.我可以通过键入 python.exe 来运行它.可以用同样的方式运行脚本.

我安装了 Python 2.7.11 64 位.

解决方案

我可以重现您的错误的唯一方法是将我的 python.exe 文件替换为一个名为 python.exe 的新空文本文件.

第一步

我注意到您提到您将 C:\Python27所有子目录 添加到您的 PATH.我首先建议从您的路径中删除所有子目录(仅保留父目录).确保在进行此更改后重新启动 Powershell 以引入新值.然后对其进行测试,看看是否解决了问题.

替代解决方案

另一种可能性是您路径上的某个地方有损坏的 python.exe 或其他一些 cmdlet、函数或脚本文件,这些文件影响了您的 Python 安装.您可以尝试从 powershell 中运行:

Get-Command python |选择对象 -ExpandProperty 定义

查看powershell实际引用的内容.*如果返回的唯一值是C:\Python27\python.exe,那么我可能会建议重新安装.

注意事项:

[*] - 取自 https://stackoverflow.com/a/16949127/1468125

When I type python in PowerShell I get an error like:

Program 'python' failed to execute: The system cannot find the file specified
At line:1 char:11
+ python.exe <<<< .
At line:1 char:1
+  <<<< python.exe
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed

I have added C:\Python27 and its sub directories to PATH. I can run it by typing python.exe. Can run scripts the same way.

I installed Python 2.7.11 64 bit.

解决方案

The only way I can reproduce your error is if I replace my python.exe file with a new empty text file named python.exe.

First Steps

I notice you mentioned that you added C:\Python27 and all subdirectories to your PATH. I would first suggest to remove all the subdirectories (just leaving the parent directory) from your path. Make sure you restart Powershell after making this change to pull in the new values. Then test it to see whether this has resolved the issue.

Alternative solution

The other possibility is that somewhere on your path you have either a corrupted python.exe or some other cmdlet, function or script file that is shadowing your python installation. You could try running from within powershell:

Get-Command python | Select-Object -ExpandProperty Definition

to see what powershell is actually referencing.* If the only value returned is C:\Python27\python.exe then I would probably suggest a reinstall.

Notes:

[*] - Taken from https://stackoverflow.com/a/16949127/1468125

这篇关于无法在powershell上运行python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆