51

I am trying to install TensorFlow in Python. I am getting the following error message, I tried uninstalling NumPy and re-installing NumPy but still getting the same error message. How to resolve this issue?

AttributeError: module 'numpy' has no attribute 'typeDict'
2
  • 2
    What versions are you using, numpy etc. This may be too soon to use numpy 1.24. Other packages might not have adjusted to the changes, especially the deprecated features. Commented Dec 19, 2022 at 17:49
  • 1
    I just posted a solution that does not involve degrading the version of any library, check it out. Commented Sep 26, 2023 at 7:57

14 Answers 14

66

I was trying to use the package pyensembl and ran into this same issue. I was able to work around it for now with

pip install numpy==1.21

Which should suffice until some of these less active packages are able to update to the new API.

Sign up to request clarification or add additional context in comments.

1 Comment

this fixes the issue with tensorflow's dependencies, thanks!
14

I did get this exact error while trying to import TensorFlow after installation, but I was able to get around this by upgrading the h5py library. There is no need to degrade the NumPy library, as doing so might cause compatibility issues with other libraries that rely on the upgraded version.

pip install --upgrade h5py

If you check the error message well, you will notice these lines, which state the possible causes:

File “h5py\h5t.pxd”, line 14, in init h5py.conv
File “h5py\h5t.pyx”, line 293, in init h5py.h5t
File "C:\Users\user\anaconda3\envs\myenv\lib\site-packages\numpy_init.py", line 320, in getattr
raise AttributeError("module {!r} has no attribute ")

The solution that does not involve degrading any library is to upgrade the h5py library.

3 Comments

Upgrading h5py worked for me as well. I did conda install -c conda-forge h5py=3.9
Exactly, but it will still work without specifying the h5py version conda install -c conda-forge h5py.
This worked for me. Before, importing keras_tuner did not only get a depration warning, but an error that caused the scrpit to stop. This did the trick, now running on numpy 1.24.3 without issues
11

As we can see in NumPy 1.21.0 Release Notes

np.typeDict is a deprecated alias for np.sctypeDict and has been so for over 14 years

(6689502).

A deprecation warning will now be issued whenever getting np.typeDict.

(gh-17586)

This means you are using a NumPy version that removed the deprecated ways AND the library you are using wasn't updated to match that version (uses something like np.typeDict instead of np.sctypeDict).

You have at least three options now

  1. Report the issue and wait until it gets fixed by TensorFlow.
  2. Use an older version of numpy (one before it started to issue the deprecation warning) and wait for it to be fixed.
  3. Change np.typeDict to np.sctypeDict wherever is being used.

Comments

8

For me pip install numpy==1.21 created more problems,

I resolved it by using '1.22.1' version

Comments

1

Spacy still hasnt upgraded to latest numpy versions. I degraded numpy to 1.21 and that worked.

Comments

1

I encountered the same error "module 'numpy' has no attribute 'typeDict'" after I installed a new version of Numpy. I was using Scipy for my project, and I found a message related to Scipy when I loaded Scipy, like from scipy.optimize import least_squares in the project.

My solution to this error is to update the mismatch packages that depend on Numpy, which is to run the following:

pip install --upgrade scipy

If you are using other packages that depend on Numpy, please check the error messages and upgrade these packages that may help you to fix this problem. Hope this also works for you.

Best wish.

Comments

1

My problem was caused by having an older version of matplotlib. After updating, the error went away:

pip install --upgrade matplotlib

Comments

1

I had the same issue. I tried following command and it worked for me:

python -m pip install --upgrade h5py

Found it here.

Comments

0

I had the same issue. I restarted the kernel and the issue was gone. Try restarting your kernel if you have the correct version of tensorflow and numpy.

Comments

0

You have to degrade your Numpy and pandas version, everything depends on the version that tensorflow supports. No other solution for now

Comments

0

I was able to solve this by upgrading the scipy package to 1.10.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
0

In my case I had a conda environment with Python 3.9.12, numpy was in version 1.25.0.

I solved the problem by updating Keras with:

conda update keras

Keras version was 2.10.0. After gathering the kernel everything worked fine.

Comments

0

In my case, I need to set PYTHONPATH='' when using a virtualenv to avoid this error.

Comments

0
AttributeError                            Traceback (most recent call last)
Cell In\[1\], line 7
5 from bs4 import BeautifulSoup # biblioteca para o pré processamento de textos
6 import random # números aleatórios
\----\> 7 import seaborn as sns #  para geração de gráficos
8 import matplotlib.pyplot as pyplot # para gráficos tb

File \~/.local/lib/python3.8/site-packages/seaborn/__init__.py:5
3 from .utils import \*  # noqa: F401,F403
4 from .palettes import \*  # noqa: F401,F403
\----\> 5 from .relational import \*  # noqa: F401,F403
6 from .regression import \*  # noqa: F401,F403
7 from .categorical import \*  # noqa: F401,F403

File \~/.local/lib/python3.8/site-packages/seaborn/relational.py:21
13 from .utils import (
14     adjust_legend_subtitles,
15     \_default_color,
(...)
18     \_scatter_legend_artist,
19 )
20 from .\_compat import groupby_apply_include_groups
\---\> 21 from .\_statistics import EstimateAggregator, WeightedAggregator
22 from .axisgrid import FacetGrid, \_facet_docs
...
318     return Tester
\--\> 320 raise AttributeError("module {!r} has no attribute "
321                      "{!r}".format(__name__, attr))

AttributeError: module 'numpy' has no attribute 'typeDict'

I was having this problem and was solved upgrading the scipy package to 1.10.1.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.