Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Poetry fails to install tensorflow

I've got a poetry project. My environment is Conda 22.9.0 on a windows machine with poetry version 1.2.2:

This is my pyproject.toml file:

[tool.poetry]
name = "myproject"
version = "0.1.0"
description = ""

[tool.poetry.dependencies]
# REVIEW DEPENDENCIES
python = ">=3.7,<3.11"
numpy = "*"
tensorflow = "^2.8"

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

[tool.poetry.scripts]
start = "myproject.main:start"

The myproject\main.py module contains:

import tensorflow as tf

def start():
    if tf.test.is_gpu_available():
        print("TensorFlow is using a GPU.")
    else:
        print("TensorFlow is NOT using a GPU.")

If I do poetry install, it seems to work fine:

Creating virtualenv myproject in D:\Projects\myproject\dev\myproject-series-forecast\.venv
Updating dependencies
Resolving dependencies...

Writing lock file

Package operations: 41 installs, 0 updates, 0 removals

• Installing certifi (2022.12.7)
• Installing charset-normalizer (2.1.1)
• Installing idna (3.4)
• Installing pyasn1 (0.4.8)
• Installing urllib3 (1.26.13)
• Installing cachetools (5.2.0)
• Installing oauthlib (3.2.2)
• Installing rsa (4.9)
• Installing six (1.16.0)
• Installing zipp (3.11.0)
• Installing requests (2.28.1)
• Installing pyasn1-modules (0.2.8)
• Installing google-auth (2.15.0)
• Installing importlib-metadata (5.2.0)
• Installing requests-oauthlib (1.3.1)
• Installing markupsafe (2.1.1)
• Installing absl-py (1.3.0)
• Installing grpcio (1.51.1)
• Installing numpy (1.21.6)
• Installing tensorboard-data-server (0.6.1)
• Installing markdown (3.4.1)
• Installing tensorboard-plugin-wit (1.8.1)
• Installing protobuf (3.19.6)
• Installing werkzeug (2.2.2)
• Installing google-auth-oauthlib (0.4.6)
• Installing astunparse (1.6.3)
• Installing flatbuffers (22.12.6)
• Installing gast (0.4.0)
• Installing google-pasta (0.2.0)
• Installing h5py (3.7.0)
• Installing keras (2.11.0)
• Installing tensorflow-estimator (2.11.0)
• Installing packaging (22.0)
• Installing opt-einsum (3.3.0)
• Installing libclang (14.0.6)
• Installing tensorboard (2.11.0)
• Installing tensorflow-io-gcs-filesystem (0.29.0)
• Installing termcolor (2.1.1)
• Installing typing-extensions (4.4.0)
• Installing wrapt (1.14.1)
• Installing tensorflow (2.11.0)

Installing the current project: myproject (0.1.0)

But when executing poetry run start I got error in import

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "D:\Python\Anaconda3\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "D:\Projects\myproject\dev\myproject-series-forecast\myproject\main.py", line 3, in <module>
    import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
like image 728
chrx Avatar asked Dec 07 '25 05:12

chrx


2 Answers

For anyone dealing with the error message:

Unable to find installation candidates for tensorflow-io-gcs-filesystem (0.32.0)

It's because of the version not compatible with the tensorflow version you're trying to install (see compatibility here). For example, if you're trying to install tensorflow 2.10.*, you need to explicitly define the appropriate version of tensorflow-io-gcs-filesystem in the .toml file (i.e., tensorflow-io-gcs-filesystem = "0.27.0").

Then proceed with downloading tensorflow (i.e., poetry add tensorflow@~2.10)

like image 60
fareed ayman Avatar answered Dec 08 '25 17:12

fareed ayman


I can confirm that for TF 2.11 this indeed an issue. Can't give you a definite answer as to why this no longer works, but it seems to be metadata related. Pip has no issues installing it, as already mentioned in the comments.

2.10 still works in poetry, not that that helps.

like image 20
Blizz Avatar answered Dec 08 '25 19:12

Blizz