tensorflow: ModuleNotFoundError tensorflow.python' is not a package

Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10 Home
  • TensorFlow version (use command below): 2.0
  • Python version: 3.6.7 and 3.7.4

Describe the current behavior When trying to import Tensorflow using this line: import tensorflow as tf

I get this error:

Traceback (most recent call last): File “singlestock/code.py”, line 1, in <module> import tensorflow as tf File “D:\documenten\programs\Python\3.6.7\lib\site-packages\tensorflow_init_.py”, line 98, in <module> from tensorflow_core import * File “D:\documenten\programs\Python\3.6.7\lib\site-packages\tensorflow_core_init_.py”, line 40, in <module> from tensorflow.python.tools import module_util as _module_util ModuleNotFoundError: No module named ‘tensorflow.python.tools’; ‘tensorflow.python’ is not a package

Describe the expected behavior I shouldn’t get this error. I should just be able to import tensorflow and then use it.

Code to reproduce the issue Provide a reproducible test case that is the bare minimum necessary to generate the problem.

This is the code which doesn’t work for me: I’ve tried this in python 3.7 and 3.6.

import tensorflow as tf

tensor = tf.convert_to_tensor([[1, 2, 3, 4], [2, 3, 4, 5]], tf.int32)
print("hello")

I don’t think the issue is in the code though, but I have no idea what the problem could be.

Other info / logs Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

error:

Traceback (most recent call last): File “singlestock/code.py”, line 1, in <module> import tensorflow as tf File “D:\documenten\programs\Python\3.6.7\lib\site-packages\tensorflow_init_.py”, line 98, in <module> from tensorflow_core import * File “D:\documenten\programs\Python\3.6.7\lib\site-packages\tensorflow_core_init_.py”, line 40, in <module> from tensorflow.python.tools import module_util as _module_util ModuleNotFoundError: No module named ‘tensorflow.python.tools’; ‘tensorflow.python’ is not a package

code:

import tensorflow as tf

tensor = tf.convert_to_tensor([[1, 2, 3, 4], [2, 3, 4, 5]], tf.int32)
print("hello")

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 29 (1 by maintainers)

Most upvoted comments

@R0b4, I had the same problem when I unimaginatively named file for the tutorial I was following csv.py.

It broke the execution of another tutorial example.py in the same directory with described symptomes.

After renaming csv.py problem resolved.

@R0b4 Both csv.py and code.py clash with modules from python standard library. Placing them in the working directory messes tensorflow import.

Hey all, I just had a similar issue due to completely different causes - mainly versioning and pip binary aliases - so I figured I’ll share what worked for me :

python3 --version
python3 -m pip install --upgrade pip
python3 -m pip install tensorflow

On my system python3 links to version 3.6.9, just be sure to have a compatible one.

Cheers 👍

I can confirm issue with import statements. Just installed tensorflow on the clean system using pip (Python 3.7.0), this installs tensorflow 2.0.

When I try to execute my code I get

ModuleNotFoundError: No module named 'tensorflow.python.tools'; 'tensorflow.python' is not a package

Looking in the site-packages, it seems directory layout in tensorflow 2.0 was changed and now there is no tensorflow.python but there is tensorflow_core.python. And this is the reason for this import error.

@R0b4 Both csv.py and code.py clash with modules from python standard library. Placing them in the working directory messes tensorflow import.

巨感谢,目录有个csv.py改名后,我又可以愉快的玩耍了