Skip to content
Happy Programming Guide
Start learning
Python

AttributeError: Module NumPy Has No Attribute typeDict

This error means a library is calling a NumPy alias that was removed in NumPy 1.24. Here is how to identify which package, and the three ways to fix it.

Keys of a mechanical keyboard seen up close

AttributeError: module 'numpy' has no attribute 'typeDict' means some library on your machine is written for an older NumPy. np.typeDict was deprecated and then removed in NumPy 1.24. Your own code almost certainly did not call it — an outdated package did. The fix is to upgrade that package, or to pin NumPy below 1.24 until you can.

What the error looks like#

Output
Traceback (most recent call last):
  File "analyse.py", line 3, in <module>
    import scipy.io
  File ".../site-packages/somepackage/compat.py", line 41, in <module>
    _types = np.typeDict
             ^^^^^^^^^^^
AttributeError: module 'numpy' has no attribute 'typeDict'

Notice that the failing line is not in your file. It is in a package inside site-packages. That package is the one that needs attention.

Why it happens#

np.typeDict was an old, undocumented alias for np.sctypeDict, a dictionary mapping type names to NumPy types. NumPy deprecated it, warned about it for several releases, and removed it in version 1.24 as part of a general clean-up of legacy aliases.

Libraries that had not been updated in a while — older releases of scipy, pandas, statsmodels, gensim, various scientific packages — then broke the moment someone installed them alongside a current NumPy.

Step 1: find out which package#

Terminal
python -c "import numpy; print(numpy.__version__)"
pip list | grep -i -E "numpy|scipy|pandas|scikit|statsmodels"

Then read the traceback again. The last frame before the error names the file, and the folder just after site-packages is the package name. That is what you upgrade.

Fix 1: upgrade the offending package (preferred)#

Terminal
pip install --upgrade scipy          # or whichever package the traceback named

Nearly every actively maintained library fixed this within weeks of the NumPy 1.24 release. Upgrading is the correct fix because it moves you forward rather than freezing an old dependency in place.

If several packages are involved, upgrade them together so pip can resolve a consistent set:

Terminal
pip install --upgrade numpy scipy pandas scikit-learn

Fix 2: pin NumPy below 1.24 (temporary)#

When the package is unmaintained and you cannot replace it today:

Terminal
pip install "numpy<1.24"

Record it so the environment is reproducible:

Output
numpy<1.24

Treat this as a note to yourself, not a solution. Pinned old dependencies stop receiving security fixes and eventually conflict with something else you need.

Terminal
python -m venv .venv
source .venv/bin/activate       # .venv\Scripts\activate on Windows
pip install -r requirements.txt

Fix 3: patch it yourself, if the code is yours#

If the failing line is in code you control, the replacement is direct:

Python
import numpy as np

# Old
types = np.typeDict

# New
types = np.sctypeDict

For a third-party package you cannot upgrade, a compatibility shim imported before the package will get you moving, though it is a last resort:

Python
import numpy as np

if not hasattr(np, "typeDict"):
    np.typeDict = np.sctypeDict

import theoldpackage      # import after the shim

Leave a comment explaining why the shim exists and what would let you delete it. Unexplained monkey-patches are how a temporary fix becomes permanent.

The other removals from the same clean-up#

If you hit one of these, you will probably hit the others. The pattern is the same — NumPy removed aliases for built-in Python types:

Removed Use instead
np.int int or np.int64
np.float float or np.float64
np.bool bool or np.bool_
np.object object
np.str str
np.typeDict np.sctypeDict

The general form of the error message is AttributeError: module 'numpy' has no attribute 'X', so once you recognise one you recognise all of them.

Preventing it next time#

Terminal
# One environment per project
python -m venv .venv

# Record exactly what works
pip freeze > requirements.txt

# Reproduce it elsewhere
pip install -r requirements.txt

Most “it worked yesterday” dependency errors come from installing packages globally, where one project’s upgrade silently changes another project’s environment.

Questions people ask#

Why does the error mention numpy when I did not import it?

Something you imported imports NumPy. Scientific and data libraries almost all depend on it, so it is loaded even when your own file never mentions it.

Which NumPy version removed typeDict?

Version 1.24. It was deprecated for several releases beforehand, which is why the same code may have produced only a warning on an earlier version.

Is np.sctypeDict a drop-in replacement?

For the common uses, yes — it is the same mapping under its proper name. If you are relying on unusual entries, check them, because neither name is part of the documented public API.

Conda instead of pip?

The same logic applies: conda update scipy, or conda install "numpy<1.24" to pin. Avoid mixing conda and pip installs of the same package in one environment.

Where to go next#

Python virtual environments, and why they end dependency chaosRead next

Keep reading

Python

Web Scraping and Automation

How to scrape a web page with Python responsibly: requests and BeautifulSoup, reading robots.txt, rate limiting, and when to use an API…

5 min read

Keep going — pick your next guide

The fastest way to improve is to read one guide, then build the thing it describes. Start with the basics, or jump straight to a project.

Ask a question or share what worked

Your email address will not be published. Required fields are marked *