Help! I have downloaded tensorflow but I can't import it

I have downloaded tensorflow with pip install. But when I use “import tensorflow as tf”, here comes the error" AttributeError: module ‘numpy’ has no attribute ‘typeDict’". In order to solve it, I have upgraded numpy(to 1.24.3) and tensorflow(to 2.13.0), but it didn’t work. Below are the screenshots. Need your help :pray:

Please don’t post pictures of text, atleast on my tablet its unreadable.
See About the Python Help category that describes how to format text in the here.

sorry about that.
the code is :

import tensorflow as tf

and the error is “AttributeError: module ‘numpy’ has no attribute ‘typeDict’”
AttributeError Traceback (most recent call last)
----> 1 import tensorflow as tf

D:\Anaconda\lib\site-packages\ in
36 import typing as _typing
—> 38 from import module_util as _module_util
39 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader

D:\Anaconda\lib\site-packages\tensorflow\ in
43 from tensorflow.python import distribute
44 # from tensorflow.python import keras
—> 45 from tensorflow.python.feature_column import feature_column_lib as feature_column
46 # from tensorflow.python.layers import layers
47 from tensorflow.python.module import module

D:\Anaconda\lib\site-packages\tensorflow\python\feature_column\ in
17 # pylint: disable=unused-import,line-too-long,wildcard-import,g-bad-import-order
—> 18 from tensorflow.python.feature_column.feature_column import *
19 from tensorflow.python.feature_column.feature_column_v2 import *
20 from tensorflow.python.feature_column.sequence_feature_column import *

D:\Anaconda\lib\site-packages\tensorflow\python\feature_column\ in
141 from tensorflow.python.framework import sparse_tensor as sparse_tensor_lib
142 from tensorflow.python.framework import tensor_shape
→ 143 from tensorflow.python.layers import base
144 from tensorflow.python.ops import array_ops
145 from tensorflow.python.ops import array_ops_stack

D:\Anaconda\lib\site-packages\tensorflow\python\layers\ in
14 # =============================================================================
15 “”“Contains the base Layer class, from which all layers inherit.”“”
—> 16 from tensorflow.python.keras.legacy_tf_layers import base
18 InputSpec = base.InputSpec

D:\Anaconda\lib\site-packages\tensorflow\python\ in
24 # See b/110718070#comment18 for more details about this import.
—> 25 from tensorflow.python.keras import models
27 from tensorflow.python.keras.engine.input_layer import Input

D:\Anaconda\lib\site-packages\tensorflow\python\keras\ in
20 from tensorflow.python.keras import metrics as metrics_module
21 from tensorflow.python.keras import optimizer_v1
—> 22 from tensorflow.python.keras.engine import functional
23 from tensorflow.python.keras.engine import sequential
24 from tensorflow.python.keras.engine import training

D:\Anaconda\lib\site-packages\tensorflow\python\keras\engine\ in
30 from tensorflow.python.keras.engine import input_spec
31 from tensorflow.python.keras.engine import node as node_module
—> 32 from tensorflow.python.keras.engine import training as training_lib
33 from tensorflow.python.keras.engine import training_utils
34 from tensorflow.python.keras.saving.saved_model import network_serialization

D:\Anaconda\lib\site-packages\tensorflow\python\keras\engine\ in
51 from tensorflow.python.keras.mixed_precision import loss_scale_optimizer as lso
52 from tensorflow.python.keras.mixed_precision import policy
—> 53 from tensorflow.python.keras.saving import hdf5_format
54 from tensorflow.python.keras.saving import save
55 from tensorflow.python.keras.saving import saving_utils

D:\Anaconda\lib\site-packages\tensorflow\python\keras\saving\ in
35 # pylint: disable=g-import-not-at-top
36 try:
—> 37 import h5py
39 except ImportError:

D:\Anaconda\lib\site-packages\ in
44 _errors.silence_errors()
—> 46 from ._conv import register_converters as _register_converters
47 _register_converters()

h5py\h5t.pxd in init h5py._conv()

h5py\h5t.pyx in init h5py.h5t()

D:\Anaconda\lib\site-packages\ in getattr(attr)
318 return Tester
→ 320 raise AttributeError("module {!r} has no attribute "
321 “{!r}”.format(name, attr))

AttributeError: module ‘numpy’ has no attribute ‘typeDict’

Firstly, if using Python from Anaconda, use Anaconda’s package manager conda, not pip.

If you’re going to continue digging (in the hole you’ve dug for yourself, instead of getting out of the hole by using conda), then normally you would’ve done the right thing by upgrading the dependency to the latest version. However numpy’s API has changed in the past between minor versions, or libraries using it rely on its implementation details. Tensorflow 2.13.0 therefore has a pinned requirement on numpy 1.23.5, not 1.24.3

numpy is frequently involved in dependency conflicts, so it’s an especially good idea to also install numpy into a venv, not your global system Python.


Thank you very much! The issue has been solved.