NameError when using input() with Python 3.4
Question: I am a new Python user and I have been working through a number of tutorials.
This has included running some of the code from the Command Prompt. This
worked fine when I first tested the code but for some reason it seems to have
stopped working and I am now getting errors when using Input(). I have
included the code below and the error message I am receiving.

Code:

    
    
       import sys
    print (sys.version)
    
    print("hello world")
    myName = input("What is your name?")
    print(myName)
    
    if (myName == "Matt"):
        print("Matt is great!")
    elif (myName == "Bob"):
        print("Bob is ok")
    else:
        print("Hello world")
    
    input("Press enter to continue")
    

Error Message:

    
    
    C:\Users\matt.xxxx>cd C:\Python34\Scripts\Projects
    
    C:\Python34\Scripts\Projects>helloworld.py
    2.7.7 (default, Jun  1 2014, 14:21:57) [MSC v.1500 64 bit (AMD64)]
    hello world
    What is your name?Matt
    Traceback (most recent call last):
      File "C:\Python34\Scripts\Projects\helloworld.py", line 6, in <module>
        myName = input("What is your name?")
      File "<string>", line 1, in <module>
    NameError: name 'Matt' is not defined
    
    C:\Python34\Scripts\Projects>
    

I know this can occur when using older versions of python, however I have
checked and I am fairly sure I am using version 3.4 (checked using import sys
etc.). I have recently installed PyCharm which is the only thing I can think
of that has changed. The code works in PyCharm and from IDLE but not from the
Command Prompt. Any help would be much appreciated.


Answer: From your example , I believe you are running the script using -
`helloworld.py` \- this would cause Windows to lookup the default application
associated with the extension `.py` and run it.

I am guessing in your case when you installed PyCharm, it somehow made Python
2.7.7 the default application for `.py` files (Or it was like that from the
start) so when you directly run `.py` files (even from command prompt) they
run using Python 2.7.7 .

You said in your comment that when running `python` directly from command
prompt, you are getting python 3.4 , so the easiest way to fix your issue
would be to use that to run your script.

Run it using the command -

    
    
    python helloworld.py
    

As a long term solution, you may want to consider changing the default
application associated with `.py` files. You can checkout [this
link](http://www.7tutorials.com/how-associate-file-type-or-protocol-program)
for guide on how to do that

