Common causes
- A typo in the variable name — Python names are case-sensitive (myVar ≠ myvar)
- You're using a variable before assigning a value to it
- The variable was defined inside a function and you're trying to use it outside
- A required import is missing — you used a function from a module you didn't import
How to fix it
- Check the spelling and case of the variable name exactly
- Make sure the variable is defined before the line that uses it
- Add the missing import: import <module> or from <module> import <name>
- For variables defined in functions, return them or declare them global if needed
Example
Traceback (most recent call last):
File "app.py", line 3, in <module>
print(username)
NameError: name 'username' is not definedPrinting a variable called 'username' that was never assigned a value
Have a different error?
Paste any error message into the Error Translator to get an instant explanation.
