Nameerror: name by is not defined

Nameerror: name by is not defined

Are you having a hard time dealing with the Python nameerror: name by is not defined error message? In this article, we’ll show you how you can fix this error. Continue reading …

Read more

Nameerror uninitialized constant

Nameerror uninitialized constant

The nameerror uninitialized constant is an error message that occurs when you are working with Ruby. If you’re struggling to fix this error don’t worry, we’ve got your back. In …

Read more

Nameerror: name ‘null’ is not defined

Nameerror: name 'null' is not defined

The nameerror: name ‘null’ is not defined is an error message you may encounter when running Python code. If you’re unfamiliar with this error message and wondering how to resolve it. …

Read more

Nameerror: name ‘xrange’ is not defined

Nameerror: name 'xrange' is not defined 460 

How to fix the Python nameerror: name ‘xrange’ is not defined error message? In this article, we’ll hand you the solutions to this python xrange is not defined. If this …

Read more

Nameerror name df is not defined

nameerror name df is not defined

Are you stuck with this Python nameerror name df is not defined error message? We understand that this error be frustrating, especially if you don’t know how to fix it. In this …

Read more

Nameerror: name plt is not defined

Nameerror name 'plt' is not defined

In this article, we will walk you through how to fix the Python nameerror: name ‘plt’ is not defined error. So, if this error gives you a headache, keep on …

Read more

Nameerror name ‘x’ is not defined

Nameerror name 'x' is not defined

In this article, we’ll show you how to fix Python nameerror name ‘x’ is not defined error message. If you’re new to this error, it might be hard for you to resolve …

Read more

Nameerror name np is not defined

Nameerror name np is not defined

When working with Python, you might encounter the error message nameerror name ‘np’ is not defined. Today, we will walk you through what this error means and how to fix …

Read more

Nameerror name ‘raw_input’ is not defined

Nameerror name 'raw_input' is not defined

Struggling to fix the Python nameerror name ‘raw_input’ is not defined error message? Errors are inevitable, and it’s frustrating when you don’t know how to resolve them. Well, in this article, we …

Read more

[Fixed] NameError: Name Model Is Not Defined in Python

Nameerror name 'model' is not defined

How to fix the Python nameerror name ‘model’ is not defined  error message? If you’re struggling with this error message, keep on reading! In this article, we’ll delve into how to …

Read more

[Fixed] NameError: Name Spark Is Not Defined in Python

nameerror: name 'spark' is not defined

Are you dealing with Python nameerror: name ‘spark’ is not defined  error message right now? And you’re having a hard time trying to figure out how to fix the name ‘spark’ is …

Read more

[Fixed] NameError: Name List Is Not Defined in Python

Nameerror: name 'list' is not defined

The Python nameerror: name ‘list’ is not defined error message can be frustrating if you don’t know how to fix it. Luckily, in this article, we’ll discuss the solutions for nameerror name list …

Read more

[Fixed] NameError: Name File Is Not Defined in Python

Nameerror: name '__file__' is not defined

The error message nameerror: name ‘__file__’ is not defined raised when you use the file global variable in an interactive shell. In addition to that, the error occurs when Python …

Read more

Frequently Asked Questions

What is the difference between NameError and UnboundLocalError?
NameError means Python looked in all reachable scopes and never found the name. UnboundLocalError means Python found the name as a local variable but you tried to use it before it was assigned. Both are about names, but UnboundLocalError happens specifically inside functions when you read a local before writing it.
I imported the module, why is the alias not defined?
You probably did import numpy but then used np.array(...). Either change the import to import numpy as np, or use the full name numpy.array(...). The alias only exists if you create it with as.
Why does "name 'display' is not defined" happen?
display() is a built-in inside Jupyter notebooks (provided by IPython), but it does not exist in regular Python scripts. To use it outside Jupyter, explicitly import: from IPython.display import display. Better yet, replace it with print() or repr() if you do not need the rich notebook output.
Why does "name 'raw_input' is not defined" happen?
You are running Python 3 code that uses raw_input() from Python 2. In Python 3, raw_input was renamed to input. Replace every raw_input(...) with input(...). The old input() from Python 2 (which evaluated input as code) is gone, Python 3's input() always returns a string.
Why does "name '__file__' is not defined" happen in Jupyter?
The __file__ attribute exists when Python imports a module from a file, it holds that file's path. Jupyter cells are not loaded from a file path, so __file__ does not exist in notebook scope. For notebooks, use os.getcwd() to get the working directory, or hardcode the path you need.
How do I prevent NameError?
(1) Use a linter (pyflakes, ruff, pylint), they catch undefined names before runtime. (2) Use an IDE with import suggestions (VS Code Python extension, PyCharm). (3) Run mypy or pyright in CI, type checkers catch most undefined-name bugs. (4) For notebooks, restart the kernel and run all cells top-to-bottom occasionally to ensure no hidden state.
How often is this NameError reference updated?
New posts are added as we hit them in real projects. Existing posts are revised when major Python versions ship changes. Last refreshed: May 2026.