简体   繁体   English

使用python代码时出现cmd错误

[英]cmd error while using python code

I am new to the process of learning programming. 我是学习编程过程的新手。 So I am going to learn Python for my first scripting language. 因此,我将学习第一种脚本语言的Python。 I downloaded Python 3.6.2 and wrote the simple "hello world " program in IDLE- it works just fine 我下载了Python 3.6.2,并在IDLE中编写了简单的“ hello world”程序-运行正常

And then I tried to open the file in command prompt and it was showing a syntax error as the below. 然后,我尝试在命令提示符下打开文件,并显示如下语法错误。

C:\Users\User>cd \Code

C:\Users\User>cd \Code

C:\Code>
C:\Code>hello.py


  File "C:\Code\hello.py", line 1


 Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)] on win32
             ^


SyntaxError: invalid syntax

C:\Code>

my pc is a windows 10 and 64 bits 我的电脑是Windows 10和64位

I searched for the solution and I couldn't find any. 我搜索了解决方案,但找不到任何解决方案。 Please reply me if you have a solution 如果您有解决方案,请回复我

thank you!! 谢谢!!

I'm not familiar with Windows cmd, but in Linux, we usually run python from terminal as 我不熟悉Windows cmd,但在Linux中,我们通常从终端运行python

python3 filename.py

or make filename.py an executable and run ./filename.py 或将filename.py设为可执行文件并运行./filename.py

when you want to run a python file using cmd, you have to prefix python to execute your program. 当您想使用cmd运行python文件时,必须在python前缀以执行程序。
In this case, type python hello.py and see the magic! 在这种情况下,键入python hello.py并查看魔术!

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

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