I opened up a Jupyter notebook and tried importing tensorflow as tf and got the following error message
JavaScript
x
2
1
import tensorflow as tf
2
And here’s the message I received
JavaScript
1
80
80
1
ImportError Traceback (most recent call last)
2
~anaconda3libsite-packagestensorflowpythonpywrap_tensorflow.py in <module>
3
57
4
---> 58 from tensorflow.python.pywrap_tensorflow_internal import *
5
59
6
7
~anaconda3libsite-packagestensorflowpythonpywrap_tensorflow_internal.py in <module>
8
27 return _mod
9
---> 28 _pywrap_tensorflow_internal = swig_import_helper()
10
29 del swig_import_helper
11
12
~anaconda3libsite-packagestensorflowpythonpywrap_tensorflow_internal.py in swig_import_helper()
13
23 try:
14
---> 24 _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
15
25 finally:
16
17
~anaconda3libimp.py in load_module(name, file, filename, details)
18
241 else:
19
--> 242 return load_dynamic(name, filename, file)
20
243 elif type_ == PKG_DIRECTORY:
21
22
~anaconda3libimp.py in load_dynamic(name, path, file)
23
341 name=name, loader=loader, origin=path)
24
--> 342 return _load(spec)
25
343
26
27
ImportError: DLL load failed: The specified module could not be found.
28
29
During handling of the above exception, another exception occurred:
30
31
ImportError Traceback (most recent call last)
32
<ipython-input-1-622d614f2d45> in <module>
33
----> 1 import tensorflow as tf
34
2
35
3 #from tensorflow.keras import layers
36
4 #from tensorflow.keras import losses
37
5 #from tensorflow.keras import preprocessing
38
39
~anaconda3libsite-packagestensorflow__init__.py in <module>
40
39 import sys as _sys
41
40
42
---> 41 from tensorflow.python.tools import module_util as _module_util
43
42 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader
44
43
45
46
~anaconda3libsite-packagestensorflowpython__init__.py in <module>
47
48 import numpy as np
48
49
49
---> 50 from tensorflow.python import pywrap_tensorflow
50
51
51
52 # Protocol buffers
52
53
~anaconda3libsite-packagestensorflowpythonpywrap_tensorflow.py in <module>
54
67 for some common reasons and solutions. Include the entire stack trace
55
68 above this error message when asking for help.""" % traceback.format_exc()
56
---> 69 raise ImportError(msg)
57
70
58
71 # pylint: enable=wildcard-import,g-import-not-at-top,unused-import,line-too-long
59
60
ImportError: Traceback (most recent call last):
61
File "C:UsersNameanaconda3libsite-packagestensorflowpythonpywrap_tensorflow.py", line 58, in <module>
62
from tensorflow.python.pywrap_tensorflow_internal import *
63
File "C:UsersNameanaconda3libsite-packagestensorflowpythonpywrap_tensorflow_internal.py", line 28, in <module>
64
_pywrap_tensorflow_internal = swig_import_helper()
65
File "C:UsersNameanaconda3libsite-packagestensorflowpythonpywrap_tensorflow_internal.py", line 24, in swig_import_helper
66
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
67
File "C:UsersNameanaconda3libimp.py", line 242, in load_module
68
return load_dynamic(name, filename, file)
69
File "C:UsersNameanaconda3libimp.py", line 342, in load_dynamic
70
return _load(spec)
71
ImportError: DLL load failed: The specified module could not be found.
72
73
74
Failed to load the native TensorFlow runtime.
75
76
See https://www.tensorflow.org/install/errors
77
78
for some common reasons and solutions. Include the entire stack trace
79
above this error message when asking for help.
80
I tried installing it with the following commands
JavaScript
1
7
1
# install pip in the virtual environment
2
conda install pip
3
# install Tensorflow CPU version
4
pip3 install --upgrade tensorflow # for python 3.*
5
# install Keras (Note: please install TensorFlow first)
6
pip install Keras
7
But I’m still getting the same error message. I’m using windows 10 if that helps.
Oh I also checked in my command line to see if it was working in python by doing
JavaScript
1
3
1
python
2
>>> import tensorflow as tf
3
But I still got the same error message
Advertisement
Answer
This problem should be fixed by installing the
Microsoft Visual C++ Redistributable for Visual Studio 2019
.