AttributeError: Module ‘numpy’ Has No Attribute ‘bool’

AttributeError: module 'numpy' has no attribute 'bool' means code is using the retired np.bool alias; replace it with bool in most code, or use np.bool_ when you specifically need a NumPy scalar type. The error commonly appears when older application or dependency code runs with NumPy 1.24.x, where that alias is unavailable. First identify whether the failing line belongs to your project or an installed package, then apply the matching repair.

Use the traceback owner and missing attribute to choose the fix.

Symptom in the Traceback Likely Cause Correct Fix
A file in your project contains np.bool Your code uses a removed alias Change it to bool, or np.bool_ when a NumPy scalar is required
A file under site-packages contains np.bool An installed dependency is too old for your NumPy version Upgrade or replace that dependency
nptyping fails on np.bool8 An older nptyping release expects another removed NumPy alias Upgrade nptyping
np.__file__ points into your project folder A local numpy.py file or numpy folder is shadowing real NumPy Rename the local file or folder, remove its cache, and restart Python
You cannot update the dependency yet The project needs a temporary compatibility constraint Temporarily use a NumPy version below 1.24 and schedule the real code or dependency update

What the NumPy bool Error Means

np.bool was an old alias for Python’s built-in bool. NumPy deprecated it in version 1.20 and later removed it from the 1.24.x line. The intended replacements are:

  • bool for ordinary Boolean values and array dtypes
  • np.bool_ for a NumPy Boolean scalar

This error does not mean NumPy no longer supports Boolean arrays. Boolean arrays still work normally:

import numpy as np
mask = np.array([True, False, True], dtype=bool)

The distinction matters when a library requires a NumPy scalar rather than a standard Python Boolean:

import numpy as np
python_flag = bool(True)
numpy_flag = np.bool_(True)

For array creation and dtype= arguments, use bool unless the library’s API explicitly requires np.bool_. np.bool was deprecated in NumPy 1.20, per the NumPy 1.20 release notes.

How to Fix the NumPy bool AttributeError

Step 1: Find the File That Actually Uses np.bool

Read the traceback from the bottom upward. The last line reports the exception, while the lines immediately above it show the file and line that tried to access np.bool.

  1. Find the first traceback line containing np.bool.
  2. Check its path.
  3. Treat a file in your repository as your code.
  4. Treat a file under site-packages as dependency code.
  5. Confirm that the Python interpreter running the project is importing the NumPy installation you expect.

Run this from the same virtual environment, terminal, or interpreter that runs the failing program:

python -c "import numpy as np; print(np.__version__); print(np.__file__)"

The printed path should normally lead to your environment’s site-packages/numpy directory. If it points to a project file such as numpy.py , a local module is shadowing the installed NumPy package.

I reproduce one problem at a time in a clean virtual environment because it makes the interpreter and installed package versions unambiguous.

Step 2: Replace np.bool in Code You Own

If the traceback points to your source file, make the direct replacement and save the file.

Use bool for Boolean array dtypes:

# Old code
mask = np.asarray(values, dtype=np.bool)
# Correct code
mask = np.asarray(values, dtype=bool)

Use np.bool_ only when the code needs a NumPy scalar object:

import numpy as np
flag = np.bool_(True)

Do not fix the issue by adding a global workaround such as np.bool = bool. That monkey patch hides obsolete code, can behave differently depending on import order, and can break when a dependency expects NumPy’s actual scalar type.

After editing, verify that Boolean array creation works in the active environment:

python -c "import numpy as np; a = np.zeros(3, dtype=bool); print(a.dtype, a.tolist())"

Then rerun the test, import, notebook cell, or application command that originally failed.

Step 3: Upgrade the Dependency When the Traceback Points to site-packages

If the failing line is in an installed library, changing your own source file will not repair it. Update the package that owns the traceback through the project’s normal dependency management method, then rerun the failing import or test.

For example, if the traceback names nptyping and the missing attribute is np.bool8, upgrade nptyping:

python -m pip install --upgrade nptyping

Check whether the environment now has internally consistent declared dependencies:

python -m pip check

A package import name and its distribution name are not always identical. Identify the distribution name before updating it rather than guessing from a nested module name in the traceback.

Step 4: Use a Temporary NumPy Compatibility Pin Only When Necessary

If a required dependency cannot be upgraded immediately, a temporary NumPy constraint can get an older project running while you plan the permanent repair.

Add this constraint to the project’s dependency requirements:

numpy<1.24

Or install the constraint into an isolated environment:

python -m pip install "numpy<1.24"

Then check dependency consistency:

python -m pip check

Run the failing project command again to confirm that the import succeeds. Treat the temporary NumPy constraint as a short-term compatibility measure, not a final fix: NumPy 1.23 can still emit deprecation warnings for np.bool, so the outdated code remains in place.

When an Installed Package Owns the Failure

Match the repair to both the missing name and the package that owns the traceback.

A traceback that enters brightway2 or bw2data is a good example of why ownership matters. In an affected Brightway2 stack, NumPy 1.23.3 can produce only a deprecation warning, while NumPy 1.24.1 can stop the package from importing at bw2data/data_store.py:172. Editing an unrelated notebook or application file does not change the installed package code that contains the obsolete alias.

Start with the dependency update path:

  1. Identify the top-level package your project installed.
  2. Update it in the dependency file or environment.
  3. Rebuild or reinstall the project environment if it uses a lockfile.
  4. Run the import or test that previously failed.

The same rule applies to the exact missing name. An np.bool error in your own source usually needs a direct replacement with bool or np.bool_. An np.bool8 error inside nptyping is a library compatibility problem and is normally fixed by upgrading nptyping, not by editing your application.

Avoid editing files directly inside site-packages. Package reinstalls, environment rebuilds, and deployment steps can overwrite those changes, leaving the project unreproducible.

Rule Out a Shadowed or Wrong NumPy Installation

Sometimes the NumPy version is not the real issue. Python may be importing a local module named numpy instead of the installed package.

Common causes include:

  • A project file named numpy.py
  • A project folder named numpy
  • A stale numpy.pyc file or __pycache__ directory
  • A notebook kernel that uses a different environment from the terminal

The command below reveals the imported module location:

python -c "import numpy as np; print(np.__file__)"

If the output points into your project directory, rename the local numpy.py file or numpy directory. Remove the matching __pycache__ directory, restart the Python process or notebook kernel, and run the command again. The path should now point to the NumPy package installed in the active environment.

For notebooks, check which executable the kernel uses:

import sys
print(sys.executable)

Install or upgrade packages through that interpreter’s environment. Installing NumPy in one terminal environment does not change a notebook kernel that uses another virtual environment or Python installation.

Confirm the Repair and Prevent It From Returning

Once the import works, test the behavior that triggered the failure rather than stopping at a successful package installation. A small Boolean dtype check catches the common direct-code case:

import numpy as np
mask = np.array([True, False], dtype=bool)
assert mask.dtype == np.dtype(bool)
assert mask.tolist() == [True, False]

Use this checklist before committing or deploying the fix:

  • The traceback no longer contains np.bool or np.bool8.
  • Your project source uses bool for ordinary Boolean dtypes.
  • Code that genuinely requires a NumPy Boolean scalar uses np.bool_.
  • The project’s normal test, import, or training command completes in a clean environment.

For shared projects, keep dependencies in a requirements file, lockfile, or environment definition instead of relying on whatever happens to be installed on one machine. That makes an outdated NumPy alias fail consistently during testing rather than appearing later in a notebook, container, or deployment environment.

Frequently Asked Questions

Why Does Python Say No Module Named NumPy?

ModuleNotFoundError: No module named 'numpy' means NumPy is not installed for the Python interpreter running your code, or that you are using the wrong virtual environment. Activate the intended environment, then install NumPy through that interpreter:

python -m pip install numpy

Confirm the installation path and version with python -c "import numpy as np; print(np.__version__); print(np.__file__)". If this works in a terminal but not a notebook, the notebook is using a different kernel environment.

Is np.int Deprecated?

Yes. np.int is another deprecated alias and should usually be replaced with Python’s built-in int. Use a specific NumPy integer type such as np.int64 only when storage width, interoperability, or a library API requires that exact dtype.

How Do I Create a Boolean Array in NumPy?

Create a Boolean array with dtype=bool. NumPy stores the resulting array with its Boolean dtype without requiring the removed np.bool alias.

import numpy as np
mask = np.array([True, False, True], dtype=bool)

For a preallocated mask, use np.zeros(shape, dtype=bool) or np.ones(shape, dtype=bool).

Why Does a NumPy Boolean Object Have No Attribute replace?

A NumPy Boolean scalar is a true/false value, not text, so it does not have the string method .replace(). Keep it as a Boolean when it represents a condition:

if flag:
    process_item()

If the value is supposed to be text, fix the input or column selection that produced a Boolean instead of a string; converting it to text merely to silence the error can hide a data-quality bug.

Is None False in Python?

None is not False: None is False evaluates to False, while bool(None) evaluates to False because None is false-like in a Boolean condition. Use is None to test specifically for missing or unset values. Use if value: only when all false-like values, such as False , 0 , empty strings, and None , should be handled the same way.

None is False
bool(None)

After making the direct replacement or updating the owning dependency, rerun the original failing command in the same environment and keep the dependency change recorded with the project.