Search code examples
pythonpython-poetry

Poetry Installed TensorFlow, but Python Says 'ModuleNotFoundError: No module named tensorflow'


tensorflow python package installed using poetry is not recognised within python. (poetry version - 2.0.1)

Anyone else facing this issue? and how did you solve them?

C:\Users\username\Documents\folder>poetry add tensorflow

Using version ^2.18.0 for tensorflow

Updating dependencies Resolving dependencies... (0.9s)

Package operations: 18 installs, 0 updates, 0 removals

  • Installing markupsafe (3.0.2)
  • Installing grpcio (1.70.0)
  • Installing markdown (3.7)
  • Installing protobuf (5.29.3)
  • Installing setuptools (75.8.0)
  • Installing tensorboard-data-server (0.7.2)
  • Installing werkzeug (3.1.3)
  • Installing wheel (0.45.1)
  • Installing astunparse (1.6.3)
  • Installing gast (0.6.0)
  • Installing libclang (18.1.1)
  • Installing opt-einsum (3.4.0)
  • Installing google-pasta (0.2.0)
  • Installing flatbuffers (25.1.24)
  • Installing termcolor (2.5.0)
  • Installing tensorboard (2.18.0)
  • Installing wrapt (1.17.2)
  • Installing tensorflow (2.18.0)

Writing lock file

C:\Users\username\Documents\folder>poetry run python

Python 3.12.8 (tags/v3.12.8:2dc476b, Dec  3 2024, 19:30:04) [MSC v.1942 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'

Solution

  • tensorflow-intel has not been installed, which since you are on windows it should be.

    Please go to https://github.com/tensorflow/tensorflow/issues/75415 and encourage the tensorflow folk to put consistent metadata in all of their wheels so that cross-platform resolvers like poetry and uv can reliably derive accurate information.