从 PowerShell 运行 python 源文件 [英] Run python source file from PowerShell

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

问题描述

我正在尝试学习 Python,但是在从 Power Shell 运行源文件时遇到了一些问题.当我输入python"时,它会打开,我可以直接在 shell 中输入 python 命令.我认为这称为交互模式.但是当我尝试运行/执行源文件时,我收到一条错误消息:它说:语法错误:语法无效.

I'm trying to learn python but have some problem running source files from power shell. When I type 'python' it opens up and I can type python commands directly in the shell. I think this is called interactive mode. But when I try to run/execute a source file I get an error message: It sayys: Syntax error: invalid syntax.

我在尝试执行脚本时使用python myfile.py".

I use 'python myfile.py' when I try to execute the script.

如果我从 IDLE 运行相同的文件,它就可以正常工作.安娜知道我做错了什么?

If I run the same file from IDLE it works just fine. Ana idea what I'm doing wrong?

这里是 myfile.py.我正在运行 python 2.7

Here is myfile.py. I'm running python 2.7

 # filename: myfile.py

while True:
      s = raw_input('Enter something: ')
      if s == 'Quit':
          break
      print 'Lenght of the string is', len(s)
print 'Done'

推荐答案

您需要将 Python 可执行文件的完整路径放在命令行中才能使其工作.您可以检查并确保您的 python exe 包含在您的系统变量中的 Path 中.

You will need to put the full path of the Python executable within the command line in order for it to work. You could check and ensure that your python exe is included in your Path among your system variables.

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

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