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'
poetry install
stating that tensorflow was successfully installed). To solve this, I had to manually install withpip install tensorflow==2.11.0 --force-reinstall
after entering the virtual env withpoetry shell
. Then, the module not found error disappears. – Frisse