Import tensorflow as tf ошибка

installed from anaconda using
pip install tensorflow

OS Platform:
Windows 7 64bit
intel processor
intel hd graphic graphic card
python version 3.6.4

Have I written custom code: No
Bazel version : I don’t have
CUDA/cuDNN version : I don’t have
GPU model and memory :N\A
Exact command to reproduce : import tensorflow as tf using jupyter

(base) C:\Users\david>pip install tensorflow
Collecting tensorflow
  Downloading https://files.pythonhosted.org/packages/f4/88/980d7032b7408fcca5b0
b8d420fcd97919197a9e7acf280ab74fc7db6993/tensorflow-1.8.0-cp36-cp36m-win_amd64.w
hl (34.4MB)
    100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 34.4MB 13kB/s
Collecting astor>=0.6.0 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/b2/91/cc9805f1ff7b49f62013
6b3a7ca26f6a1be2ed424606804b0fbcf499f712/astor-0.6.2-py2.py3-none-any.whl
Collecting gast>=0.2.0 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/5c/78/ff794fcae2ce8aa6323e
789d1f8b3b7765f601e7702726f430e814822b96/gast-0.2.0.tar.gz
Requirement already satisfied: six>=1.10.0 in c:\programdata\anaconda3\lib\site-
packages (from tensorflow)
Collecting tensorboard<1.9.0,>=1.8.0 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/59/a6/0ae6092b7542cfedba6b
2a1c9b8dceaf278238c39484f3ba03b03f07803c/tensorboard-1.8.0-py3-none-any.whl (3.1
MB)
    100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 3.1MB 682kB/s
Requirement already satisfied: numpy>=1.13.3 in c:\programdata\anaconda3\lib\sit
e-packages (from tensorflow)
Collecting termcolor>=1.1.0 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/8a/48/a76be51647d0eb9f10e2
a4511bf3ffb8cc1e6b14e9e4fab46173aa79f981/termcolor-1.1.0.tar.gz
Requirement already satisfied: wheel>=0.26 in c:\programdata\anaconda3\lib\site-
packages (from tensorflow)
Collecting grpcio>=1.8.6 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/80/7e/d5ee3ef92822b01e3a27
4230200baf2454faae64e3d7f436b093ff771a17/grpcio-1.11.0-cp36-cp36m-win_amd64.whl
(1.4MB)
    100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 1.4MB 787kB/s
Collecting protobuf>=3.4.0 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/32/cf/6945106da76db9b62d11
b429aa4e062817523bb587018374c77f4b63200e/protobuf-3.5.2.post1-cp36-cp36m-win_amd
64.whl (958kB)
    100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 962kB 787kB/s
Collecting absl-py>=0.1.6 (from tensorflow)
  Downloading https://files.pythonhosted.org/packages/90/6b/ba04a9fe6aefa56adafa
6b9e0557b959e423c49950527139cb8651b0480b/absl-py-0.2.0.tar.gz (82kB)
    100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 92kB 708kB/s
Collecting bleach==1.5.0 (from tensorboard<1.9.0,>=1.8.0->tensorflow)
  Downloading https://files.pythonhosted.org/packages/33/70/86c5fec937ea4964184d
4d6c4f0b9551564f821e1c3575907639036d9b90/bleach-1.5.0-py2.py3-none-any.whl
Requirement already satisfied: werkzeug>=0.11.10 in c:\programdata\anaconda3\lib
\site-packages (from tensorboard<1.9.0,>=1.8.0->tensorflow)
Collecting markdown>=2.6.8 (from tensorboard<1.9.0,>=1.8.0->tensorflow)
  Downloading https://files.pythonhosted.org/packages/6d/7d/488b90f470b96531a3f5
788cf12a93332f543dbab13c423a5e7ce96a0493/Markdown-2.6.11-py2.py3-none-any.whl (7
8kB)
    100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 81kB 682kB/s
Collecting html5lib==0.9999999 (from tensorboard<1.9.0,>=1.8.0->tensorflow)
  Downloading https://files.pythonhosted.org/packages/ae/ae/bcb60402c60932b32dfa
f19bb53870b29eda2cd17551ba5639219fb5ebf9/html5lib-0.9999999.tar.gz (889kB)
    100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 890kB 787kB/s
Requirement already satisfied: setuptools in c:\programdata\anaconda3\lib\site-p
ackages (from protobuf>=3.4.0->tensorflow)
Building wheels for collected packages: gast, termcolor, absl-py, html5lib
  Running setup.py bdist_wheel for gast ... done
  Stored in directory: C:\Users\david\AppData\Local\pip\Cache\wheels\9a\1f\0e\3c
de98113222b853e98fc0a8e9924480a3e25f1b4008cedb4f
  Running setup.py bdist_wheel for termcolor ... done
  Stored in directory: C:\Users\david\AppData\Local\pip\Cache\wheels\7c\06\54\bc
84598ba1daf8f970247f550b175aaaee85f68b4b0c5ab2c6
  Running setup.py bdist_wheel for absl-py ... done
  Stored in directory: C:\Users\david\AppData\Local\pip\Cache\wheels\23\35\1d\48
c0a173ca38690dd8dfccfa47ffc750db48f8989ed898455c
  Running setup.py bdist_wheel for html5lib ... done
  Stored in directory: C:\Users\david\AppData\Local\pip\Cache\wheels\50\ae\f9\d2
b189788efcf61d1ee0e36045476735c838898eef1cad6e29
Successfully built gast termcolor absl-py html5lib
Installing collected packages: astor, gast, html5lib, bleach, markdown, protobuf
, tensorboard, termcolor, grpcio, absl-py, tensorflow
  Found existing installation: html5lib 1.0.1
    Uninstalling html5lib-1.0.1:
      Successfully uninstalled html5lib-1.0.1
  Found existing installation: bleach 2.1.2
    Uninstalling bleach-2.1.2:
      Successfully uninstalled bleach-2.1.2
Successfully installed absl-py-0.2.0 astor-0.6.2 bleach-1.5.0 gast-0.2.0 grpcio-
1.11.0 html5lib-0.9999999 markdown-2.6.11 protobuf-3.5.2.post1 tensorboard-1.8.0
 tensorflow-1.8.0 termcolor-1.1.0
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' comm
and.
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in swig_import_helper()
     13         try:
---> 14             return importlib.import_module(mname)
     15         except ImportError:

C:\ProgramData\Anaconda3\lib\importlib\__init__.py in import_module(name, package)
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127 

C:\ProgramData\Anaconda3\lib\importlib\_bootstrap.py in _gcd_import(name, package, level)

C:\ProgramData\Anaconda3\lib\importlib\_bootstrap.py in _find_and_load(name, import_)

C:\ProgramData\Anaconda3\lib\importlib\_bootstrap.py in _find_and_load_unlocked(name, import_)

C:\ProgramData\Anaconda3\lib\importlib\_bootstrap.py in _load_unlocked(spec)

C:\ProgramData\Anaconda3\lib\importlib\_bootstrap.py in module_from_spec(spec)

C:\ProgramData\Anaconda3\lib\importlib\_bootstrap_external.py in create_module(self, spec)

C:\ProgramData\Anaconda3\lib\importlib\_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

ImportError: DLL load failed with error code -1073741795

During handling of the above exception, another exception occurred:

ModuleNotFoundError                       Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>()
     57 
---> 58   from tensorflow.python.pywrap_tensorflow_internal import *
     59   from tensorflow.python.pywrap_tensorflow_internal import __version__

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in <module>()
     16             return importlib.import_module('_pywrap_tensorflow_internal')
---> 17     _pywrap_tensorflow_internal = swig_import_helper()
     18     del swig_import_helper

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in swig_import_helper()
     15         except ImportError:
---> 16             return importlib.import_module('_pywrap_tensorflow_internal')
     17     _pywrap_tensorflow_internal = swig_import_helper()

C:\ProgramData\Anaconda3\lib\importlib\__init__.py in import_module(name, package)
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127 

ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-306-64156d691fe5> in <module>()
----> 1 import tensorflow as tf

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\__init__.py in <module>()
     22 
     23 # pylint: disable=g-bad-import-order
---> 24 from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
     25 # pylint: disable=wildcard-import
     26 from tensorflow.tools.api.generator.api import *  # pylint: disable=redefined-builtin

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\__init__.py in <module>()
     47 import numpy as np
     48 
---> 49 from tensorflow.python import pywrap_tensorflow
     50 
     51 # Protocol buffers

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>()
     72 for some common reasons and solutions.  Include the entire stack trace
     73 above this error message when asking for help.""" % traceback.format_exc()
---> 74   raise ImportError(msg)
     75 
     76 # pylint: enable=wildcard-import,g-import-not-at-top,unused-import,line-too-long

ImportError: Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 14, in swig_import_helper
    return importlib.import_module(mname)
  File "C:\ProgramData\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 658, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 571, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 922, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed with error code -1073741795

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 16, in swig_import_helper
    return importlib.import_module('_pywrap_tensorflow_internal')
  File "C:\ProgramData\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

I installed tensorflow using the following command.

pip install tensorflow

I am running a simple program which is

import tensorflow as tf
node1 = tf.constant(3.0, tf.float32)
node2 = tf.constant(4.0) # also tf.float32 implicitly
print(node1, node2)

I am getting the following error on running the program.

Traceback (most recent call last):
File "C:\Program Files (x86)\Python\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "C:\Program Files (x86)\Python\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
File "<frozen importlib._bootstrap>", line 577, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 906, in create_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Program Files (x86)\Python\lib\site-
packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Program Files (x86)\Python\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Program Files (x86)\Python\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow_internal')
File "C:\Program Files (x86)\Python\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "first.py", line 1, in <module>
import tensorflow as tf
File "C:\Program Files (x86)\Python\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import *
File "C:\Program Files (x86)\Python\lib\site-packages\tensorflow\python\__init__.py", line 51, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Program Files (x86)\Python\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Program Files (x86)\Python\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "C:\Program Files (x86)\Python\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
File "<frozen importlib._bootstrap>", line 577, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 906, in create_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Program Files (x86)\Python\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Program Files (x86)\Python\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Program Files (x86)\Python\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow_internal')
File "C:\Program Files (x86)\Python\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow_internal'


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions.  Include the entire stack trace above this error message when asking for help.

I have updated the pip and am running the program on python 3.5

I’ve recently gone through the installation of tensorflow (and struggled a little) and when I believed I had got it, I now get these import errors when running a file that ONLY contains import tensorflow as tf, I ran the cmd: python3 tftest.py and get these import errors:

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
  File "/usr/lib/python3.4/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
ImportError: /usr/local/lib/python3.4/dist-packages/tensorflow/python/_pywrap_tensorflow.so: invalid ELF header

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "stockprice.py", line 1, in <module>
    import tensorflow as tf
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/__init__.py", line 60, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
  File "/usr/lib/python3.4/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
ImportError: /usr/local/lib/python3.4/dist-packages/tensorflow/python/_pywrap_tensorflow.so: invalid ELF header


Error importing tensorflow.  Unless you are using bazel,
you should not try to import tensorflow from its source directory;
please exit the tensorflow source tree, and relaunch your python interpreter
from there.

I do have tensorflow installed

Name: tensorflow
Version: 0.12.0
Location: /usr/local/lib/python3.4/dist-packages
Requires: numpy, six, protobuf, wheel

I’ve been trying to figure this out for hours, has anyone encountered this or a similar error? I’ve looked at installation manuals, and followed every single step I could. I’ve tried reintalling protobuf

I am not running my test file on the tensorflow directory.

I would really REALLY appreciate any help since this error is draining my brain out.

In this Python tutorial, we will discuss the error “import error no module named TensorFlow. Here we’ll cover the reason related to this error using Python. And we’ll also cover the following topics:

  • Import error no module named tensorflow.compat.v1
  • Import error no module named ‘tensorflow.contrib’
  • Import error no module named tensorflow_hub
  • Import error no module named ‘tensorflow addons’
  • Import error no module named ‘tensorflow.python.eager’
  • In this section, we will discuss the error import error no module named TensorFlow in Python.
  • Basically, this error message comes when we do not import the TensorFlow library or we can say the TensorFlow library is not installed in our system.
  • If you have not installed the TensorFlow library in your system and still want to try importing the TensorFlow library in your program then it will raise an error message ‘no module named TensorFlow.

Example:

import tensorflow as tf

tens1 = tf.Variable([[67, 89],[23, 45]])
tens2 = tf.Variable([[94, 117],[189, 210]])
new_output= tf.add(tens1,tens2)
print(new_output)

In the above code, we have used the tf.add() function and within this function, we assigned the given tensors ‘tens1’ and ‘tens2’ as an argument.

Here is the Screenshot of the following given code.

Python import error no module named TensorFlow
import error no module named TensorFlow

Now let’s see the solution for this error:

Visual Code Studio

If you have installed Visual code Studio then it will use a pip environment and if you want to import some needed libraries then you have to install via command.

  • install TensorFlow using pip command

Syntax:

Here is the Syntax of the installation of the TensorFlow library

pip install TensorFlow

This Syntax will help you to resolve the error ‘no Module named TensorFlow’

Jupyter

If you have installed Jupyter notebook then use the Conda environment. To get detailed information regarding how to install the TensorFlow library in the Conda environment. You can refer to our detailed article TensorFlow in Python.

Also, check: TensorFlow Sparse Tensor

Import error no module named ‘tensorflow.contrib’

  • Here we are going to discuss the error import error no module named ‘TensorFlow.contrib’.
  • Basically, the contrib module is not available in TensorFlow version 2.0. This module contains contributed code and it is also a volatile code.
  • The possible reason behind this error is when the interpreter cannot locate the contrib ‘module’ in the library.
  • The latest version of TensorFlow 2.x has removed the session and contrib module from the TensorFlow library.

Reason: module ‘contrib’ is not working in version 2.x

Example:

import tensorflow.contrib

Here is the Screenshot of the following given code

import error no module named 'tensorflow.contrib'
import error no module named ‘TensorFlow.contrib’

In the following given code, we have just imported the ‘TensorFlow.contrib’ module but when we executed this command it displays the No module named ‘TensorFlow.contrib’. The possible reason is this module does not work in the latest version of TensorFlow 2.x.

Let’s discuss the solution to this error

  • First, uninstall the already installed version, if it is the latest version then reinstall it with the older version. To uninstall the tensorflow 2.x you can easily use the command pip uninstall TensorFlow.
  • Now to install older version of TensorFlow 1.x you can use below command
pip install tensorflow==1.15.0

Read: Python TensorFlow reduce_sum

Import error no module named tensorflow.compat.v1

  • In this section, we are going to discuss the error no module named tensorflow.compat.v1.
  • The possible reason behind this error is that compat.v1 modules are deprecated in Tensorflow version 1.12.0. This module will help the user to write the code in both TensorFlow versions.
  • This module does not support the 1.12 version, if you want to execute this module on your system then you have to install the latest or above the 1.12 version.

Example:

import error no module named tensorflow compat v1 in Python
import error no module named TensorFlow compat v1 in Python

Now we are going to use the updated version of TensorFlow for importing the TensorFlow.compat.v1 module in Python

To install the new version of TensorFlow in Conda prompt you can use the below command

conda install tensorflow==2.6
Solution of no module named tensorflow compat v1 in Python
Solution of no module named TensorFlow compat v1 in Python

As you can see in the Screenshot we have checked the version of TensorFlow it displays 2.6 latest version and also successfully imported the TensorFlow.compat.v1.

Also, check: Module ‘TensorFlow’ has no attribute ‘session’

Import error no module named ‘tensorflow_hub’

  • In this Program, we will discuss the error no module named ‘tensorflow_hub’ in Python.
  • Basically, this error message comes when the module ‘tensorflow_hub’ is not available in the TensorFlow library package.

Example:

Python import error no module named tensorflow hub
Python import error no module named TensorFlow hub

As you can see in the Screenshot it displays no module name ‘tensorflow_hub’ the reason behind this is we are using the older version of TensorFlow 1.14. In this version, the tensorflow_hub module is not working.

Let’s have a look at the Solution to this error

To solve this error you have to install the latest version of TensorFlow in your system. By default 2.7 is a stable version and to install the updated version of TensorFlow, you can use the below command. This command is used for conda prompt users.

conda install tensorflow==2.7

Screenshot

Solution of import error no module named tensorflow hub
Solution of import error no module named TensorFlow hub

In this Screenshot, you can see that we have installed the latest version of TensorFlow 2.7 and then import the tensorflow_hub module.

Read: TensorFlow Tensor to numpy

Import error no module named ‘tensorflow addons’

  • In this section, we will discuss the error no module named ‘tensorflow addons’ in Python.
  • Basically, the addon module is available in the latest TensorFlow version 2.7 but we have to update the ‘TensorFlow addons’ module. This module is not available in core Tensorflow and it also supports optimizers, metrics, and losses.

Screenshot

import error no module named tensorflow addons
import error no module named TensorFlow addons

As you can see in the output, it displays no module name ‘tensorflow_addons’. And the possible reason is that the ‘tensorflow_addons‘ module is available in TensorFlow latest version 2.7. But we have to update the ‘tensorflow_addons’ module.

Let’s have a look at the Solution to this error

To solve this error you have to install the older version of TensorFlow in your system. By default 2.7 is a stable version but this module only does not work in the latest version 2.x.

Output:

Solution of import error no module named tensorflow addons
Solution of import error no module named TensorFlow addons

To upgrade the ‘TensorFlow addons’ module you can easily use the below command

pip install tensorflow-addons

In the above code, we have imported the tensorflow_addons() module after upgrading the module.

Read: TensorFlow global average pooling

Import error no module named ‘tensorflow.python.eager’

  • Here we are going to discuss the error no module named ‘tensorflow.python.eager’ in Python.
  • When I was trying to import the ‘TensorFlow.python.eager’ module this error comes out in output. The reason behind that is the version of the TensorFlow library.

Let’s have a look at the Solution to this error

In this example, we have just imported the TensorFlow library and then checked the version by using the tf.__version__ command. After that, we have imported the ‘tensorflow.python.eager’ module. Once you will execute this code the output displays the module has been successfully imported.

Example:

import error no module named tensorflow python eager
import error no module named tensorflow python eager

Also, take a look at some more Python TensorFlow tutorials.

  • Binary Cross Entropy TensorFlow
  • Gradient descent optimizer TensorFlow
  • Python TensorFlow Placeholder
  • Convert list to tensor TensorFlow
  • Module ‘tensorflow’ has no attribute ‘div’
  • Module ‘tensorflow’ has no attribute ‘sparse_placeholder’

So, in this tutorial, we have solved the error “import error no module named TensorFlow“. Here we’ll cover the reason related to this error using Python. And we’ll also cover the following topics:

  • import error no module named tensorflow.compat.v1
  • import error no module named ‘tensorflow.contrib’
  • import error no module named tensorflow_hub
  • import error no module named ‘tensorflow addons’
  • import error no module named ‘tensorflow.python.eager’

Fewlines4Biju Bijay

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.

As a data scientist you might have encountered an error while importing TensorFlow in your Python environment which says No module named tensorflow If youre facing this issue dont worry youre not alone In this article we will discuss what this error means and how to fix it

As a data scientist, you might have encountered an error while importing TensorFlow in your Python environment, which says “No module named ‘tensorflow’”. If you’re facing this issue, don’t worry, you’re not alone. In this article, we will discuss what this error means and how to fix it.

What is Tensorflow?

TensorFlow is an open-source machine learning library developed by Google Brain Team. It is used to build and train machine learning models, including deep learning models. TensorFlow is written in Python, C++, and CUDA, and it has become one of the most popular libraries for machine learning.

What causes the ‘No module named ‘tensorflow’’ error?

The “No module named ‘tensorflow’” error occurs when Python is unable to find the TensorFlow module in the Python environment. This error can occur due to one of the following reasons:

  1. TensorFlow is not installed: If TensorFlow is not installed in your Python environment, you will get this error. You can check if TensorFlow is installed by running the following command in your Python environment:

If TensorFlow is not installed, you will get an error saying “ModuleNotFoundError: No module named ‘tensorflow’”.

  1. Incorrect installation: If you have installed TensorFlow incorrectly, you might face this error. Make sure you have installed TensorFlow following the instructions provided in the official TensorFlow documentation.

  2. Incorrect Python environment: If you have installed TensorFlow in a different Python environment than the one you’re currently using, you will face this error. Make sure you have installed TensorFlow in the same Python environment that you’re using.

  3. Outdated TensorFlow version: If you’re using an outdated version of TensorFlow, you might face this error. Make sure you have installed the latest version of TensorFlow.

How to fix the ‘No module named ‘tensorflow’’ error

Now, let’s discuss how to fix this error.

1. Install TensorFlow

If TensorFlow is not installed in your Python environment, you need to install it. You can install TensorFlow using pip, which is a package manager for Python. To install TensorFlow using pip, run the following command in your Python environment:

This command will install the latest version of TensorFlow.

2. Check the installation

After installing TensorFlow, you can check if it is installed correctly by importing it in your Python environment. Run the following command in your Python environment:

If you don’t get any error, then TensorFlow is installed correctly.

3. Upgrade TensorFlow

If you’re using an outdated version of TensorFlow, you need to upgrade it to the latest version. You can upgrade TensorFlow using pip. Run the following command in your Python environment:

!pip install --upgrade tensorflow

This command will upgrade TensorFlow to the latest version.

4. Check the Python environment

If you have installed TensorFlow in a different Python environment than the one you’re currently using, you need to install it in the same Python environment. You can check the Python environment you’re using by running the following command:

import sys
print(sys.executable)

This command will print the path of the Python executable that you’re currently using. Make sure you have installed TensorFlow in the same Python environment.

5. Check the installation directory

If you have installed TensorFlow in a non-default directory, you need to add the directory to the Python path. You can add the directory to the Python path by running the following command in your Python environment:

import sys
sys.path.append('path/to/tensorflow')

Replace ‘path/to/tensorflow’ with the actual path to the TensorFlow installation directory.

Conclusion

In this article, we discussed the “No module named ‘tensorflow’” error that occurs while importing TensorFlow in Python. We discussed the causes of this error and how to fix it. If you’re facing this error, follow the steps mentioned in this article to fix it. TensorFlow is an essential library for machine learning, and it’s important to have it installed correctly in your Python environment to build and train machine learning models.


About Saturn Cloud

Saturn Cloud is your all-in-one solution for data science & ML development, deployment, and data pipelines in the cloud. Spin up a notebook with 4TB of RAM, add a GPU, connect to a distributed cluster of workers, and more. Join today and get 150 hours of free compute per month.

Понравилась статья? Поделить с друзьями:
  • If name main python ошибка
  • Imperator rome ошибка 0xc0000142
  • Import sqlite3 ошибка
  • Iis код ошибки 0x00000000
  • Illegal opcode hp proliant ошибка