python-poetry / poetry

Python packaging and dependency management made easy
https://python-poetry.org
MIT License
31.63k stars 2.27k forks source link

ModuleNotFoundError: No module named 'requests_toolbelt' in poetry 1.7.0 #8625

Closed nerdvegas closed 12 months ago

nerdvegas commented 1 year ago

In poetry 1.7.0 I'm getting this trace:

$ poetry run pytest -v
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/cleo/application.py", line 327, in run
    exit_code = self._run(io)
  File "/usr/local/lib/python3.10/site-packages/poetry/console/application.py", line 188, in _run
    self._load_plugins(io)
  File "/usr/local/lib/python3.10/site-packages/poetry/console/application.py", line 354, in _load_plugins
    manager.load_plugins()
  File "/usr/local/lib/python3.10/site-packages/poetry/plugins/plugin_manager.py", line 38, in load_plugins
    self._load_plugin_entry_point(ep)
  File "/usr/local/lib/python3.10/site-packages/poetry/plugins/plugin_manager.py", line 76, in _load_plugin_entry_point
    plugin = ep.load()  # type: ignore[no-untyped-call]
  File "/usr/local/lib/python3.10/importlib/metadata/__init__.py", line [162](https://gitlab-master.nvidia.com/omniverse/benchmark/reggie/-/jobs/73544227#L162), in load
    module = import_module(match.group('module'))
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/local/lib/python3.10/site-packages/poetry_plugin_export/plugins.py", line 7, in <module>
    from poetry_plugin_export.command import ExportCommand
  File "/usr/local/lib/python3.10/site-packages/poetry_plugin_export/command.py", line 12, in <module>
    from poetry_plugin_export.exporter import Exporter
  File "/usr/local/lib/python3.10/site-packages/poetry_plugin_export/exporter.py", line 11, in <module>
    from poetry.repositories.http_repository import HTTPRepository
  File "/usr/local/lib/python3.10/site-packages/poetry/repositories/http_repository.py", line 26, in <module>
    from poetry.utils.authenticator import Authenticator
  File "/usr/local/lib/python3.10/site-packages/poetry/utils/authenticator.py", line 22, in <module>
    from requests_toolbelt import user_agent
ModuleNotFoundError: No module named 'requests_toolbelt'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/bin/poetry", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/site-packages/poetry/console/application.py", line 411, in main
    exit_code: int = Application().run()
  File "/usr/local/lib/python3.10/site-packages/cleo/application.py", line 338, in run
    self.render_error(e, io)
  File "/usr/local/lib/python3.10/site-packages/poetry/console/application.py", line [180](https://gitlab-master.nvidia.com/omniverse/benchmark/reggie/-/jobs/73544227#L180), in render_error
    self.set_solution_provider_repository(self._get_solution_provider_repository())
  File "/usr/local/lib/python3.10/site-packages/poetry/console/application.py", line 400, in _get_solution_provider_repository
    from poetry.mixology.solutions.providers.python_requirement_solution_provider import (
  File "/usr/local/lib/python3.10/site-packages/poetry/mixology/solutions/providers/__init__.py", line 3, in <module>
    from poetry.mixology.solutions.providers.python_requirement_solution_provider import (
  File "/usr/local/lib/python3.10/site-packages/poetry/mixology/solutions/providers/python_requirement_solution_provider.py", line 9, in <module>
    from poetry.puzzle.exceptions import SolverProblemError
  File "/usr/local/lib/python3.10/site-packages/poetry/puzzle/__init__.py", line 3, in <module>
    from poetry.puzzle.solver import Solver
  File "/usr/local/lib/python3.10/site-packages/poetry/puzzle/solver.py", line 16, in <module>
    from poetry.puzzle.provider import Indicator
  File "/usr/local/lib/python3.10/site-packages/poetry/puzzle/provider.py", line 27, in <module>
    from poetry.packages.direct_origin import DirectOrigin
  File "/usr/local/lib/python3.10/site-packages/poetry/packages/direct_origin.py", line 14, in <module>
    from poetry.vcs.git import Git
  File "/usr/local/lib/python3.10/site-packages/poetry/vcs/git/__init__.py", line 3, in <module>
    from poetry.vcs.git.backend import Git
  File "/usr/local/lib/python3.10/site-packages/poetry/vcs/git/backend.py", line 25, in <module>
    from poetry.utils.authenticator import get_default_authenticator
  File "/usr/local/lib/python3.10/site-packages/poetry/utils/authenticator.py", line 22, in <module>
    from requests_toolbelt import user_agent
ModuleNotFoundError: No module named 'requests_toolbelt'

With the exact same pyproject.toml/poetry.lock in the same repo, run using poetry v1.6.1, I don't get this error.

Relevant info extracted from pyproject:

[tool.poetry.dependencies]
python = "^3.10"
requests = ">=2"
PyYAML = ">=3"
Jinja2 = ">=3"
pandas = "^2"
numpy = "^1"
tabulate = "^0"
pydantic = "^2.2"

SQLAlchemy = { version = "^2", optional = true }
psycopg2 = { version = "^2", optional = true }
python-gitlab = { version = "^3.12.0", optional = true }
dohq-teamcity = { version = "^1", optional = true }
boto3 = { version = "^1.26", optional = true }
networkx = { version = "^3.1", optional = true }

[tool.poetry.extras]

sqlite = ["SQLAlchemy"]  # enables sqlite storage class
postgres = ["SQLAlchemy", "psycopg2"]  # enables postgres storage class
gitlab = ["python-gitlab", "networkx"]  # enables gitlab backend
teamcity = ["python-gitlab", "dohq-teamcity"]  # enables teamcity backend
css = ["boto3"]  # enables blob storage, see 'blob_storage_mode' setting
all = [
    "SQLAlchemy", "psycopg2", "python-gitlab", "dohq-teamcity", "networkx", "boto3"
]  # meta dependency covering all extras

[tool.poetry.dev-dependencies]
pytest = "^7.1.2"
pytest-cov = "^4.1.0"

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

The error occurs when I attempt to run pytest after "poetry install -E sqlite", although I don't think it's only in that case.

eamanu commented 1 year ago

Hi @nerdvegas seems that you are running poetry 1.7.1 using the system python, IMO that would be fixed if you run apt install python3-requests-toolbelt. But you can share the poetry config --list output for both version to do a better analysis. Thanks

dimbleby commented 12 months ago

poetry correctly lists requests-toolbelt in its dependencies, so the problem is at your end and cannot be fixed from this repository.

nerdvegas commented 12 months ago

Confirmed issue my end, there was a poetry config virtualenvs.create false in the mix. The install of my app ends up removing the requests_toolbelt poetry dependency. Works fine with venv enabled.

dimbleby commented 12 months ago

then please close this

github-actions[bot] commented 8 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.