简体   繁体   English

在Windows命令提示中运行Python脚本时如何修复NameError

[英]How to fix NameError when running Python Script in Windows Command Prompt

I ran a python file, named jbA.py in windows command prompt, with the following commands, orderly: 我在Windows命令提示符中依次运行了一个名为jbA.py的python文件,其中包含以下命令:

  1. python 蟒蛇
  2. jbA.py jbA.py

It displays the following error: 它显示以下错误:

Traceback (most recent call last): 
  File "<stdin>", line 1, in <module>
NameError: name 'jbA' is not defined

Can anyone help to fix the above mentioned error? 任何人都可以帮助解决上述错误吗? Thank you. 谢谢。

when you type python you are moving to the python commandline tool. 当您键入python您将移至python命令行工具。 Now there is no context for your file jbA.py . 现在,文件jbA.py没有上下文。

To execute a python file, type python <filename>.py . 要执行python文件,请输入python <filename>.py

In your case, it is python jbA.py . 在您的情况下,它是python jbA.py For python 3.x, you may use python3 jbA.py 对于python 3.x,您可以使用python3 jbA.py

To run pyhton script open command prompt 要运行pyhton脚本,请打开命令提示符

1) for python version greater then 3:- python3 filename.py 1)适用于大于3的python版本:-python3 filename.py

2) for python version 2:- python filename.py 2)适用于python版本2:-python filename.py

no need to open python console 无需打开python控制台

Have you checked that python is in your Environment PATH variable list? 您是否检查过python在环境PATH变量列表中? Try typing 尝试输入

python --version

in your windows command prompt and see if you get an error. 在Windows命令提示符下,查看是否出现错误。 If it does not return a version number, it has not been added to your PATH. 如果未返回版本号,则说明该版本号尚未添加到您的PATH中。 If you don't know how to do this, refer to this link - https://www.java.com/en/download/help/path.xml 如果您不知道如何执行此操作,请参考此链接-https://www.java.com/en/download/help/path.xml

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

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