tensorflow: TensorFlow 2.15 cannot be imported after Poetry install on Windows
Issue type
Bug
Have you reproduced the bug with TensorFlow Nightly?
No
Source
binary
TensorFlow version
2.15.0
Custom code
No
OS platform and distribution
Windows
Mobile device
No response
Python version
3.11
Bazel version
No response
GCC/compiler version
No response
CUDA/cuDNN version
No response
GPU model and memory
No response
Current behavior?
I expect to be able to install and import TensorFlow on the python:3.11-windowsservercore Docker container, using Poetry.
I made a new project with the following pyproject.toml, copied from Poetry issue 8271
[tool.poetry]
name = "project-tf"
version = "0.1.0"
description = ""
authors = [""]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.10,<3.12"
# Issue between poetry and tensorflow metadata since >=2.11
# This is a temporary workaround
# related to https://github.com/python-poetry/poetry/issues/8271
# Inspired from https://github.com/tensorflow/tensorflow/blob/adb39b04e9cb116df4659a7e2de9eea27e62f25c/tensorflow/tools/pip_package/setup.py#L148-L162
tensorflow = {version = "^2.13.0" }
tensorflow-macos = { version = "^2.13.0", platform = "darwin", markers = "platform_machine=='arm64'" }
tensorflow-intel = { version = "^2.13.0", platform = "win32" }
tensorflow-cpu = [
{ version = "^2.13.0", platform = "linux", markers = "platform_machine!='arm64' and platform_machine!='aarch64'" },
{ version = "^2.13.0", platform = "darwin", markers = "platform_machine!='arm64' and platform_machine!='aarch64'" },]
tensorflow-cpu-aws = { version = "^2.13.0", platform = "linux", markers = "platform_machine=='arm64' or platform_machine=='aarch64'" }
# https://github.com/tensorflow/tensorflow/blob/adb39b04e9cb116df4659a7e2de9eea27e62f25c/tensorflow/tools/pip_package/setup.py#L107-L108
# https://github.com/python-poetry/poetry/issues/8271#issuecomment-1697740447
tensorflow-io-gcs-filesystem = [
{ version = ">= 0.23.1", markers = "platform_machine!='arm64' or platform_system!='Darwin'" },
{ version = "< 0.32.0", markers = "platform_system == 'Windows'" }
]
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Then, I generate the lock file and on the Docker container python:3.11-windowsservercore, and install my package with
# Allow long file paths, or otherwise installing TensorFlow fails.
Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem -Name LongPathsEnabled -Value 1
# Install Microsoft Visual C++ Redistributable, or otherwise importing TensorFlow fails.
Invoke-WebRequest -Uri https://aka.ms/vs/17/release/vc_redist.x64.exe -OutFile .\VC_redist.x64.exe
.\VC_redist.x64.exe /install /quiet /norestart
# Install Poetry.
pip install poetry==1.7.1
# Install this package and run the tests.
poetry install
Finally, pytest fails as soon as it tries to import TensorFlow.
The reason for this behavior is described at Poetry issue 8271.
Standalone code to reproduce the issue
See above.
Relevant log output
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 20 (9 by maintainers)
This issue seems to be fixed by TensorFlow 2.19. See the following pyproject.toml based on Poetry 2.
Hi, running into the same issue, is it’s possible to make “tensorflow-io-gcs-filesystem” an optional dependency? in most use cases where you install it on windows, you’re probably won’t going to need those extra file systems, and if you do, you can always use WSL like the tensorflow-io suggests - this will still allow the usage of tensorflow-cpu on windows without pinning a version of an external dependency while allow those who needs this dependency to continue to get it.
Hi @RRiva, yes the fix for automatic installation of tensorflow-intel using poetry, will be available with the next release. I will contact tensorflow/io team to check the latest release of tensorflow-io-gcs-filesystem on the Windows platform
Hi @RRiva, the issue has been addressed in https://github.com/tensorflow/tensorflow/issues/58674#issuecomment-1593891706 I just successfully imported TF 2.15 on the Windows using the Poetry tool. Before running the command poetry add tensorflow==2.15.0 please run the command poetry add tensorflow-io-gcs-filesystem==0.31.0 TF 2.15 supports Python 3.9-3.11, please add it in the pyproject.toml
I’ve fixed it using this comment: manually specifying the versions in the pyproject.toml.
Hi, I just checked if the installation improved with TF 2.16, but unfortunately nothing has changed for Windows:
tensorflow-intelstill needs to be specified as a requirement, since it’s not found automatically.tensorflow-io-gcs-filesystemdoes not provide recent Windows wheels, and therefore does not support python 3.12.I hope that the fix that you mentioned will be available with the next release 🙂
Thank you @RRiva, yes Intel releases tensorflow-intel for the Windows platform. In pip installation, TensorFlow-intel is automatically installed while installing TensorFlow on the Windows platform. We are working to fix it for Poetry Installation as well which should be available in the TF 2.16 release
Hi @RRiva, please run the command below to fix your issue. poetry add tensorflow-intel