在 PowerShell 中运行 Python? [英] Running Python in PowerShell?

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

问题描述

我正在尝试使用 Zed A. Shaw 的指南艰难地学习 Python" 来学习 Python 的基础知识.我遇到的问题是我可以运行 Python 脚本,但只能在名称前使用 .\ .这会打开 CMD 一瞬间然后关闭.

I am attempting to learn the very basics of Python using the guide "Learn Python the hard way" by Zed A. Shaw. The problem that I am having is that I can run Python scripts, but only when using .\ in front of the name. This opens up CMD for a split second and then closes.

如果我尝试运行该文件,它会返回该文件不是可运行的程序文件、脚本等.

If I attempt to run the file it returns that the file is not an operable program file, script, etc..

我在 Stack Overflow 上发现了多个与此问题相关的问题,但没有一个解决方案对我有用.

I've found multiple questions on Stack Overflow that relate to this question, but none of the solutions have worked for me.

我尝试过的两件事:

[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "User")

$env:PATH =$env:PATH+";."

来源:(如何取消 PowerShell 要求脚本和可执行文件以.\"开头?)

当我检查环境变量 PATH 时,它包含正确的路径,那么还有什么其他原因会导致这种情况?

When I check the environment variable PATH it has the correct path within it, so what other things could be causing this?

推荐答案

因为,您可以在 PowerShell 中运行 Python.你可以只做 python .py 来运行脚本.因此,对于名为 test.py 的脚本,包含

Since, you are able to run Python in PowerShell. You can just do python <scriptName>.py to run the script. So, for a script named test.py containing

name = raw_input("Enter your name: ")
print "Hello, " + name

PowerShell 会话将是

The PowerShell session would be

PS C:\Python27> python test.py
Enter your name: Monty Python
Hello, Monty Python
PS C:\Python27>

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

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