46

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.
    – hpaulj
    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.
    – Comsavvy
    Sep 26 at 7:57

10 Answers 10

58

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.

1
  • this fixes the issue with tensorflow's dependencies, thanks!
    – mike gold
    May 29 at 18:38
8

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.
5

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

I resolved it by using '1.22.1' version

3

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.

2
  • Upgrading h5py worked for me as well. I did conda install -c conda-forge h5py=3.9
    – felixm
    Sep 29 at 18:48
  • Exactly, but it will still work without specifying the h5py version conda install -c conda-forge h5py.
    – Comsavvy
    Oct 2 at 16:41
1

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

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.

0

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

0

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

1
  • 1
    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.
    – Community Bot
    May 13 at 13:31
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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.