question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error while importing tensorflow from Spyder

See original GitHub issue

I am able to import tensorflow from python terminal outside of Spyder editor but unfortunately, it is showing an error while importing tensorflow package. Error is listed below:


import tensorflow as tf

2022-04-28 21:44:42.471112: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll
Error in callback <bound method AutoreloadMagics.post_execute_hook of <autoreload.AutoreloadMagics object at 0x000001E4926584C8>> (for post_execute):
Traceback (most recent call last):

  File "C:\Users\suman\miniconda3\envs\TF15\lib\site-packages\IPython\extensions\autoreload.py", line 538, in post_execute_hook
    _, pymtime = self._reloader.filename_and_mtime(sys.modules[modname])

  File "C:\Users\suman\miniconda3\envs\TF15\lib\site-packages\IPython\extensions\autoreload.py", line 184, in filename_and_mtime
    if not hasattr(module, '__file__') or module.__file__ is None:

  File "C:\Users\suman\miniconda3\envs\TF15\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
    module = self._load()

  File "C:\Users\suman\miniconda3\envs\TF15\lib\site-packages\tensorflow\__init__.py", line 44, in _load
    module = _importlib.import_module(self.__name__)

  File "C:\Users\suman\miniconda3\envs\TF15\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)

  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import

  File "<frozen importlib._bootstrap>", line 983, in _find_and_load

  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked

  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked

  File "<frozen importlib._bootstrap_external>", line 728, in exec_module

  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed

  File "C:\Users\suman\miniconda3\envs\TF15\lib\site-packages\tensorflow_core\contrib\__init__.py", line 39, in <module>
    from tensorflow.contrib import compiler

  File "C:\Users\suman\miniconda3\envs\TF15\lib\site-packages\tensorflow_core\contrib\compiler\__init__.py", line 21, in <module>
    from tensorflow.contrib.compiler import jit

  File "C:\Users\suman\miniconda3\envs\TF15\lib\site-packages\tensorflow_core\contrib\compiler\__init__.py", line 22, in <module>
    from tensorflow.contrib.compiler import xla

  File "C:\Users\suman\miniconda3\envs\TF15\lib\site-packages\tensorflow_core\contrib\compiler\xla.py", line 22, in <module>
    from tensorflow.python.estimator import model_fn as model_fn_lib

  File "C:\Users\suman\miniconda3\envs\TF15\lib\site-packages\tensorflow_core\python\estimator\model_fn.py", line 26, in <module>
    from tensorflow_estimator.python.estimator import model_fn

  File "C:\Users\suman\miniconda3\envs\TF15\lib\site-packages\tensorflow_estimator\__init__.py", line 10, in <module>
    from tensorflow_estimator._api.v1 import estimator

  File "C:\Users\suman\miniconda3\envs\TF15\lib\site-packages\tensorflow_estimator\_api\v1\estimator\__init__.py", line 10, in <module>
    from tensorflow_estimator._api.v1.estimator import experimental

  File "C:\Users\suman\miniconda3\envs\TF15\lib\site-packages\tensorflow_estimator\_api\v1\estimator\experimental\__init__.py", line 10, in <module>
    from tensorflow_estimator.python.estimator.canned.dnn import dnn_logit_fn_builder

  File "C:\Users\suman\miniconda3\envs\TF15\lib\site-packages\tensorflow_estimator\python\estimator\canned\dnn.py", line 27, in <module>
    from tensorflow_estimator.python.estimator import estimator

  File "C:\Users\suman\miniconda3\envs\TF15\lib\site-packages\tensorflow_estimator\python\estimator\estimator.py", line 36, in <module>
    from tensorflow.python.profiler import trace

ImportError: cannot import name 'trace' from 'tensorflow.python.profiler' (C:\Users\suman\miniconda3\envs\TF15\lib\site-packages\tensorflow_core\python\profiler\__init__.py)


Warning
It seems you're trying to use a module that doesn't come with our installer. Check this FAQ in our docs to learn how to do this.




Anyone, please help me to fix it.

I am using Windows 11 and the latest Spyder editor.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
dalthvizcommented, Apr 28, 2022

@SanjuSoni you will need to manually downgrade tensorflow-estimator to 1.15 (not sure why but conda install tensorflow-gpu=1.15 installs tensorflow-estimator 2.6.0 which I would say is incompatible with tensorflow 1.15.0). For that, run from an Anaconda prompt with your env activated conda install tensorflow-estimator=1.15

This issue is not directly related with Spyder but let us know if the above helps

4reactions
sumantkrsonicommented, Apr 29, 2022

You are Genius @dalthviz SIr.

It works for both environments TF15 and Tf2 after degrading the tensorflow-estimator.

In TF15 env

import tensorflow as tf

2022-04-29 11:48:54.814574: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll

tf.version Out[2]: ‘1.15.0’

=========================

In TF2 env

import tensorflow as tf

tf.version Out[2]: ‘2.6.0’

===========================

Thanks for your valuable support!!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

No module named 'tensorflow' in spyder | windows + ... - GitHub
But when I tried to import tensorflow in spyder: ... Tensorflow 2.0 GPU error: Failed to load the native TensorFlow runtime. #28134.
Read more >
can not import TensorFlow in Spyder or Python ...
2 Answers 2 · Run the anaconda prompt as administrator.(right click-> run as administrator). · pip uninstall tensorflow. · Close anaconda prompt.
Read more >
ModuleNotFoundError: No module named 'tensorflow' in Python
The Python "ModuleNotFoundError: No module named 'tensorflow'" occurs when we forget to install the tensorflow module before importing it or ...
Read more >
Build and install error messages - TensorFlow
Error importing tensorflow. Unless you are using bazel, you should not try to import tensorflow from its source directory; please exit the tensorflow...
Read more >
Tutorial: Anaconda + Spyder + TensorFlow 2.0 @ Windows 10
In this story, I will install Anaconda, Spyder and TensorFlow 2.0 in ... TensorFlow 2.0 Installation; Spyder Installation; Import TensorFlow ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found