Immutable solution version
ImportError: cannot import name 'bool' from 'numpy'
Complete solution
Fixes ImportError: cannot import name 'bool' from 'numpy' Use when the traceback shows `from numpy import bool` (or int, float, complex, object, unicode, str) and you run numpy 1.24 or newer Not for: the error is `ModuleNotFoundError: No module named 'numpy'` (numpy is not installed) or a binary/ABI mismatch error
How to fix ImportError: cannot import name 'bool' from 'numpy'
Stop importing the alias. In your own code replace from numpy import bool with the builtin bool (or np.bool_ if you need the numpy scalar type). If the error comes from a library you do not own (chumpy is the classic carrier), upgrade that library, or pin numpy<1.24 as a stopgap. numpy 1.24 removed the old aliases np.bool, np.int, np.float and friends for good.
The exact error
ImportError: cannot import name 'bool' from 'numpy'Fix it
Find the bad import:
grep -rn "from numpy import" --include=*.py .and look for bool, int, float, complex, object, unicode, str. Expected: you see the exact line raising the errorIn your own code, swap the alias for the builtin:
from numpy import boolgoes away, just usebool. Only keep numpy'snp.bool_if you truly need the numpy scalar. Expected: import succeeds on numpy>=1.24If the traceback points inside a third-party package (chumpy is the classic), upgrade that package; if no fixed release exists, pin
numpy<1.24in your requirements. Expected: pip shows numpy 1.23.x and the import works
When this applies
the traceback shows from numpy import bool (or int, float, complex, object, unicode, str) and you run numpy 1.24 or newer
When this does NOT apply
the error is ModuleNotFoundError: No module named 'numpy' (numpy is not installed) or a binary/ABI mismatch error
Versions
numpy >= 1.24, Python 3.8+
Why it happens
numpy deprecated these aliases in 1.20 and removed them in 1.24. Old code and old libraries still import them.
Edge cases
np.bool_ still exists and is fine to use. Pinning numpy<1.24 is a band-aid; the real fix is updating the importing code.
Evidence
Asked about: ImportError: cannot import name 'bool' from 'numpy' (gh:jxyjxyw/stereo-inertial-poser (README known-issues)). The verified fix: Stop importing the alias. In your own code replace from numpy import bool with the builtin bool (or np.bool_ if you need the numpy scalar type). If the error comes from a library you do not own (chumpy is the classic carrier), upgrade that library, or pin numpy<1.24 as a stopgap. numpy 1.24 removed the old aliases np.bool, np.int, np.float and friends for good. Full thread: https://github.com/jxyjxyw/stereo-inertial-poser/blob/HEAD/README.md
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_I2H8wX2kW66ZVbdC_uw-9g" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">ImportError: cannot import name 'bool' from 'numpy' <span>— Vectle</span></a>