ModuleNotFoundError: No module named 'google' when using Natural Language - python

I'm testing out the Natural Language API from Google but this line
from google.cloud import language_v1
is throwing the following error
ModuleNotFoundError: No module named 'google'
I am using Poetry and my pyproject.toml contains google-cloud
[tool.poetry]
name = "cocoon"
version = "0.1.0"
description = ""
authors = ["Your Name <you#example.com>"]
[tool.poetry.dependencies]
python = "^3.9"
pandas = "^1.2.3"
app-store-scraper = "^0.3.5"
google-cloud-language = "^2.0.0"
google-api-python-client = "^2.0.2"
google-cloud = "^0.34.0"
fsspec = "^0.8.7"
[tool.poetry.dev-dependencies]
pytest = "^5.2"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
What I am following is based on these docs at Google.
There are similar questions (like this or this) but no solution has worked for me so far. I am not using a venv as outlined there since I am using Poetry. I have also double-checked on VSCode that the interpreter is correct.

Related

Install a python repo from setup.py in poetry

I'm trying to install pl_cross repository using poetry. In the README it's indicated that it must be installed running python setup.py install. When I try to install the repo adding it to my pyproject.toml file:
[tool.poetry]
name = "iq_segmentator"
version = "0.1.0"
description = "Speed up Deep Learning semantic segmentation projects."
authors = ["Jeremiah Poveda Martínez <jere#qubiotech.com>"]
[tool.poetry.dependencies]
python = "3.9"
wandb = "0.12.18"
nibabel = "4.0.1"
torch = "1.11.0"
pytorch-lightning = "1.6.4"
torchmetrics = "0.9.1"
monai = "0.9.0"
hydra-core = "1.2.0"
black = "22.3.0"
pytest = "7.1.2"
numpy = "1.22.4"
matplotlib = "3.5.2"
pl_cross = {git = "https://github.com/SkafteNicki/pl_cross.git", branch="master"}
sphinx = {version = "5.0.2", optional = true}
sphinxcontrib-napoleon = {version = "0.7", optional = true}
sphinx-rtd-theme = {version = "1.0.0", optional = true}
[tool.poetry.scripts]
pl_cross = "pl_closs:setup"
[tool.poetry.extras]
docs = ["sphinx", "sphinx-rtd-theme", "sphinxcontrib-napoleon"]
[tool.poetry.dev-dependencies]
mlflow = "^1.26.1"
pydra = "^0.18"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
I get the following error:
Updating dependencies
Resolving dependencies... (4.8s)
PackageInfoError
Unable to determine package info for path: /tmp/pypoetry-git-pl_crossah48_3rm
Fallback egg_info generation failed.
Command ['/tmp/tmpfc8t0g_3/.venv/bin/python', 'setup.py', 'egg_info'] errored with the following return code 1, and output:
Traceback (most recent call last):
File "/tmp/pypoetry-git-pl_crossah48_3rm/setup.py", line 15, in <module>
import pl_cross
File "/tmp/pypoetry-git-pl_crossah48_3rm/pl_cross/__init__.py", line 40, in <module>
from .datamodule import BaseKFoldDataModule, KFoldDataModule
File "/tmp/pypoetry-git-pl_crossah48_3rm/pl_cross/datamodule.py", line 5, in <module>
import torch
ModuleNotFoundError: No module named 'torch'
at ~/.poetry/lib/poetry/inspection/info.py:500 in _pep517_metadata
496│ try:
497│ venv.run_python("setup.py", "egg_info")
498│ return cls.from_metadata(path)
499│ except EnvCommandError as fbe:
→ 500│ raise PackageInfoError(
501│ path, "Fallback egg_info generation failed.", fbe
502│ )
503│ finally:
504│ os.chdir(cwd.as_posix())
NOTE: I have torch installed. Could someone point out what is causing the error? Is is possible to isntall packages this way with poetry? Is this documented?
Poetry is not able to parse the needed metadata (package name, version and dependencies) from the setup.py. This is why a wheel package needs to be build where Poetry can obtain these information.
Building the wheel is done in a clean, temporary environment and all build-dependencies mentioned in the pyproject.toml according to PEP-518 are installed into this.
The problem with pl_cross is, that within the setup.py pl_cross is imported, which in return imports other modules and dependencies, which are not installed in the build environment.
Please contact the maintainer of this project and ask them to refactor it, so that the unnecessary imports doesn't happen.

Using pyproject.toml with flexible version from datetime

We version all our company packages with a simple datetime version. Now we are considering moving to pyproject.toml instead of setup.py. Is it possible to do flexible versioning there as well?
version = datetime.datetime.now().strftime('%Y.%m.%d.%H%M')
# Actual setup
setup(
name="some-package",
version=version,
description='Some description',
packages=find_namespace_packages(where='src', include=['company.project.*']),
package_dir={'': 'src'},
python_requires='>=3.6',
install_requires=[
'numpy',
'numba'
],
)
What syntax do I need to adjust the versioning in the pyproject.toml? This one is using poetry but there is no need for that.
[tool.poetry]
name = "some-package"
version = "0.1.0"
description = ""
readme = "README.md"
Poetry does not seem to support that, see issue #4299 for example.
But Flit does. Flit allows us to declare the version as "dynamic" in pyproject.toml:
[project]
name = 'some_package'
dynamic = ['version']
description = 'Description of the package.'
[build-system]
requires = ['flit_core>=3.2,<4']
build-backend = 'flit_core.buildapi'
The version is then determined by the package's __version__ attribute. For example, __init__.py could contain this:
import datetime
__version__ = datetime.datetime.now().strftime('%Y.%m.%d.%H%M')
Note, however, that in your specific case, when building the package with flit build, Flit will observe that the version number does not comply with PEP 440 and normalize it accordingly, i.e. remove leading zeros from day and month numbers.

Repl.it: Package operation failed on repl.it freeCodeCamp

i'm trying to get certificate on freeCodeCamp by making project on repl.it . Everything goes well until this happened. I don't know what happen, i have search it on google but i still didn't understand. I appreciate for your help
Python 3.8.2 (default, Feb 26 2020, 02:56:10)
>
Repl.it: Updating package configuration
--> python3 -m poetry lock
[RuntimeError]
The Poetry configuration is invalid:
- 'description' is a required property
exit status 1
Repl.it: Package operation failed
Add description="" between [tool.poetry] and [tool.poetry.dependencies]
Example :
[tool]
[tool.poetry]
authors = ["Your Name <you#example.com>"]
description=""
name = "root"
version = "0.0.0"
[tool.poetry.dependencies]
pandas = "*"
python = "^3.7"
seaborn = "*"

Poetry - [AttributeError] 'bool' object has no attribute 'strip'

I am using poetry as a dependency manager for python, and when I'm trying to install the dependencies using poetry:
poetry install
I get this error:
$ poetry install
Installing dependencies from lock file
[AttributeError]
'bool' object has no attribute 'strip'
Any ideas on what possibly can cause this error on happening because It doesn't let the dependencies install...
Example of pyproject.toml
[tool.poetry]
name = "orex"
version = "0.1.0"
description = ""
[tool.poetry.dependencies]
python = "^3.8"
fastapi = ">=0.52.0"
SQLAlchemy = ">=1.3.12"
pydantic = {extras = ["email"], version = "^1.3"}
click = "^7.0"
alembic = "^1.3.2"
uvicorn = "^0.11.1"
passlib = "^1.7.2"
Change
pydantic = {extras = ["email"], version = "^1.3"}
to
pydantic = "{extras = ['email'], version = '^1.3'}"

poetry tries to install project folder as a dependency: EnvCommandError

I am trying to run poetry install command, but I get the following error:
[EnvCommandError]
Command ['pip', 'install', '-e', '<PROJECT_FOLDER_PATH>'] errored with
the following return code 1, and output:
Obtaining file:///<PROJECT_FOLDER_PATH>
ERROR: Package '<subfolder>' requires a different Python: 3.6.8 not in '>=3.7,<4.0'
Where my project directory containing .toml file is marked as <PROJECT_FOLDER> (PROJECT_FOLDER_PATH is, correspondingly, it's full path), and it contains <subfolder>.
Part of my toml file:
[tool.poetry]
name = "<PROJECT_FOLDER>"
version = "0.1.0"
description = ""
authors = ["Your Name <you#example.com>"]
[tool.poetry.dependencies]
python = "^3.7"
It seems that poetry tries to install the project itself as a dependency, but for some reason that I don't understand it seems the conflicting Python version. I temporarily solved it by setting python = "^3.6", but now the issue is back, as I need some package which only accepts python = "^3.7".

Categories

Resources