Ajinkya Ghadge
Ajinkya Ghadge

Reputation: 103

ImportError: No module named 'tensorflow.core'

After installing tensorflow-gpu using pip3, I am getting the following error when trying to import tensorflow as tf

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dlpda/.local/lib/python3.5/site-packages/tensorflow/__init__.py", line 22, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/home/dlpda/.local/lib/python3.5/site-packages/tensorflow/python/__init__.py", line 52, in <module>
    from tensorflow.core.framework.graph_pb2 import *
ImportError: No module named 'tensorflow.core'

Although I am able to import successfully in a virtualenv, but not outside.

How should I resolve this problem to be able to import tensorflow?

Upvotes: 9

Views: 16996

Answers (5)

Ovtchinnikov
Ovtchinnikov

Reputation: 1

For my issue (Error importing: No module named 'tensorflow.core.kernels.boosted_trees') this worked out:

pip3 install --force-reinstall tensorflow

Upvotes: 0

Rohit Gupta
Rohit Gupta

Reputation: 453

I was facing the same issue in tensorflow 1.15 with django 2.1.0 and python 3.7.4

It was working fine with tensorflow 1.14 with django 2.1.0 and python 3.7.4.

There is some issue in latest version of tensorflow(2.0/1.15) with previous version of django. same issue is observed with previous version of flask also.

https://github.com/tensorflow/tensorflow/issues/34607

Proposed solution is to update your django version from 2.1.0 > 2.2.5 , it works for me.

Upvotes: 0

sjr
sjr

Reputation: 9885

This is probably a bug in tensorflow. In 1.13, we have an __init__.py that contains:

__all__ = [_s for _s in dir() if not _s.startswith('_')]

# ... later ...
try:                                                                                                                                                                       
  del python
  del core

So while we remove python and core from the module, we do not remove them from __all__. This prevents use cases like from tensorflow import *. This should be fixed in Tensorflow 1.14 with this change.

Upvotes: 3

Dhiraj Rai
Dhiraj Rai

Reputation: 11

Please create a virtual environment and then install tensorflow into that. It works fine.

Upvotes: 1

Shashikant Ghangare
Shashikant Ghangare

Reputation: 51

The problem may be with packages installation directories like some packages are installed in home and some in /usr/. I suggest you to remove all the packages in home directory by finding them in ~/.local/lib/python3.5/site-packages and reinstall then with super user privileges.

Upvotes: 2

Related Questions