简体   繁体   中英

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:

  1. python
  2. 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. Now there is no context for your file jbA.py .

To execute a python file, type python <filename>.py .

In your case, it is python jbA.py . For python 3.x, you may use python3 jbA.py

To run pyhton script open command prompt

1) for python version greater then 3:- python3 filename.py

2) for python version 2:- python filename.py

no need to open python console

Have you checked that python is in your Environment PATH variable list? Try typing

python --version

in your windows command prompt and see if you get an error. If it does not return a version number, it has not been added to your PATH. If you don't know how to do this, refer to this link - https://www.java.com/en/download/help/path.xml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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