poetry: Tensorflow 2.13.0 cannot be imported after install
- Poetry version: Poetry (version 1.5.1)
- Python version: Python 3.11.4
- OS version and name: macOS Ventura 13.3 M2 Chip
macOS-13.3-arm64-arm-64bit
- pyproject.toml: pyproject.toml
- I am on the latest stable Poetry version, installed using a recommended method.
- I have searched the issues of this repo and believe that this is not a duplicate.
- I have consulted the FAQ and blog for any relevant entries or release notes.
- If an exception occurs when executing a command, I executed it again in debug mode (
-vvv
option) and have included the output below.
Issue
After installing tensorflow 2.13.0 with above pyproject.toml on macOs Apple Sillicon , importing fails with
ModuleNotFoundError: No module named 'tensorflow
Same method works under linux. HINT: in tensorflow 2.13 the authors introduce platform specific install for pip. Under macOs arm it is supposed to install tensorflow-macos . under linux there is another dependency tree
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 9
- Comments: 27 (7 by maintainers)
For people still looking for a full combo workaround, this should work for tensorflow 2.11 in all situations (in reality I haven’t tested everything). Don’t hesitate to comment with your problems so that we improve on this. I’ve tested :
This should work with windows, new mac, old mac, docker in new mac, amd and non-amd linux machines … EDIT : Tested :
Currently, I advise to copy the full code below in your
pyproject.toml
in the poetry’s dependencies. Using a poetry group,[tool.poetry.group.tensorflow.dependencies]
section could be a good thing to be able to isolate it :EDIT : I fixed above the tensorflow-io-gcs-filesystem issue from @RRiva EDIT 2 : adding @radoering answer EDIT 3 : fixing windows from @Vuizur
I found the solution: Wirg’s solution actually specified the wrong platform for pytorch-intel, one doesn’t have to write windows, but win32. Here is a corrected version:
@dre-hh Have using environment markers to get around the issue?
If we take a look at tensorflow/tools/pip_package/setup.py, we see that they require the tensorflow-macos package where the environment marker has been satisfied.
It’s generated, but would look something like this.
tensorflow-macos == 2.15.0 ;platform_system=="Darwin" and platform_machine=="arm64"
Following the Poetry documentation here, your dependency specification should look this.
I’d tend to agree with @dimbleby, the devs over at @tensorflow should improve the compatibility of their project with package managers, but that’s another battle entirely.
The issue has been resolved on Windows: please refer https://github.com/tensorflow/tensorflow/issues/62899#issuecomment-1935052936
https://github.com/python-poetry/poetry/issues/8271#issuecomment-1928038659
Telling users that they should manually add the dependencies that tensorflow forgot to declare is at best a workaround, not a resolution.
#1616 is about different path dependencies with the same version (and resolved), thus, not related.
It’s related to #2012 and #4046. If there is no wheel for Windows (and no sdist), you’ll want to exclude that version for Windows:
Data point: Vuizur 's solution worked for me on M2 max.
tensorflow’s metadata does not express that dependency:
No mention here of
tensorflow-macos
.I guess this is another variation on https://github.com/tensorflow/tensorflow/issues/58674
please encourage the tensorflow folk to publish consistent metadata in all of their wheels, with platform-specific variations described by markers