Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"poetry add" doesn't respect project's Python version #4166

Closed
3 tasks done
sweetgiorni opened this issue Jun 10, 2021 · 2 comments
Closed
3 tasks done

"poetry add" doesn't respect project's Python version #4166

sweetgiorni opened this issue Jun 10, 2021 · 2 comments
Labels
area/solver Related to the dependency resolver kind/bug Something isn't working as expected

Comments

@sweetgiorni
Copy link

  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: CentOS Linux release 7.9.2009
  • Poetry version: 1.1.6
  • Link of a Gist with the contents of your pyproject.toml file: pyproject.toml

Issue

I'm trying to add Jinja2 as a dependency to a Python2 project, but poetry is grabbing a version of Jinja2 that is too new. The last release to support Python2 is Jinja2==2.11.3, which is what pip install grabs. poetry tries to use 3.0.1, which doesn't work. This script reproduces the problem from scratch:

#!/bin/bash

set -ex

rm -rf test_project
poetry --version
mkdir test_project
cd test_project
poetry cache clear --all pypi -n
poetry env remove python2.7 &> /dev/null || true

poetry init --no-interaction --name 'test_project' --python '2.7.5' -vvv
poetry env use 2.7.5
poetry check
cat pyproject.toml
poetry add Jinja2 -vvv

Sample output:

+ rm -rf test_project
+ poetry --version
Poetry version 1.1.6
+ mkdir test_project
+ cd test_project
+ poetry cache clear --all pypi -n
+ poetry env remove python2.7
+ true
+ poetry init --no-interaction --name test_project --python 2.7.5 -vvv

This command will guide you through creating your pyproject.toml config.


You can specify a package in the following forms:
  - A single name (requests)
  - A name and a constraint (requests@^2.23.0)
  - A git url (git+https://github.com/python-poetry/poetry.git)
  - A git url with a revision (git+https://github.com/python-poetry/poetry.git#develop)
  - A file path (../my-package/my-package.whl)
  - A directory (../my-package/)
  - A url (https://example.com/packages/my-package-0.1.0.tar.gz)



+ poetry env use 2.7.5
Using virtualenv: /root/.cache/pypoetry/virtualenvs/test-project-5Y0SbW3t-py2.7
+ poetry check
All set!
+ poetry install -vvv
Using virtualenv: /root/.cache/pypoetry/virtualenvs/test-project-5Y0SbW3t-py2.7
Updating dependencies
Resolving dependencies...
   1: fact: test-project is 0.1.0
   1: derived: test-project
   1: selecting test-project (0.1.0)
   1: Version solving took 0.003 seconds.
   1: Tried 1 solutions.

Writing lock file

Finding the necessary packages for the current system
+ cat pyproject.toml
[tool.poetry]
name = "test_project"
version = "0.1.0"
description = ""
authors = ["me!"]

[tool.poetry.dependencies]
python = "2.7.5"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
+ poetry add Jinja2 -vvv
Using virtualenv: /root/.cache/pypoetry/virtualenvs/test-project-5Y0SbW3t-py2.7
PyPI: 39 packages found for jinja2 *
Using version ^3.0.1 for Jinja2

Updating dependencies
Resolving dependencies...
   1: fact: test-project is 0.1.0
   1: derived: test-project
   1: fact: test-project depends on Jinja2 (^3.0.1)
   1: selecting test-project (0.1.0)
   1: derived: Jinja2 (>=3.0.1,<4.0.0)
PyPI: 1 packages found for jinja2 >=3.0.1,<4.0.0
   1: fact: jinja2 (3.0.1) requires Python >=3.6
   1: derived: not jinja2 (==3.0.1)
   1: fact: no versions of jinja2 match >3.0.1,<4.0.0
   1: conflict: no versions of jinja2 match >3.0.1,<4.0.0
   1: !  Jinja2 (>3.0.1,<4.0.0) is partially satisfied by not  jinja2 (3.0.1)
   1: ! which is caused by "jinja2 (3.0.1) requires Python >=3.6"
   1: ! thus: jinja2 is forbidden
   1: !  jinja2 (>=3.0.1,<4.0.0) is satisfied by  Jinja2 (^3.0.1)
   1: ! which is caused by "test-project depends on Jinja2 (^3.0.1)"
   1: ! thus: version solving failed
   1: Version solving took 0.012 seconds.
   1: Tried 1 solutions.

  Stack trace:

  8  ~/.poetry/lib/poetry/_vendor/py3.6/clikit/console_application.py:131 in run
      129│             parsed_args = resolved_command.args
      130│ 
    → 131│             status_code = command.handle(parsed_args, io)
      132│         except KeyboardInterrupt:
      133│             status_code = 1

  7  ~/.poetry/lib/poetry/_vendor/py3.6/clikit/api/command/command.py:120 in handle
      118│     def handle(self, args, io):  # type: (Args, IO) -> int
      119│         try:
    → 120│             status_code = self._do_handle(args, io)
      121│         except KeyboardInterrupt:
      122│             if io.is_debug():

  6  ~/.poetry/lib/poetry/_vendor/py3.6/clikit/api/command/command.py:171 in _do_handle
      169│         handler_method = self._config.handler_method
      170│ 
    → 171│         return getattr(handler, handler_method)(args, io, self)
      172│ 
      173│     def __repr__(self):  # type: () -> str

  5  ~/.poetry/lib/poetry/_vendor/py3.6/cleo/commands/command.py:92 in wrap_handle
       90│         self._command = command
       91│ 
    →  92│         return self.handle()
       93│ 
       94│     def handle(self):  # type: () -> Optional[int]

  4  ~/.poetry/lib/poetry/console/commands/add.py:173 in handle
      171│             self._installer.whitelist([r["name"] for r in requirements])
      172│ 
    → 173│             status = self._installer.run()
      174│         except BaseException:
      175│             # Using BaseException here as some exceptions, eg: KeyboardInterrupt, do not inherit from Exception

  3  ~/.poetry/lib/poetry/installation/installer.py:103 in run
      101│         local_repo = Repository()
      102│ 
    → 103│         return self._do_install(local_repo)
      104│ 
      105│     def dry_run(self, dry_run=True):  # type: (bool) -> Installer

  2  ~/.poetry/lib/poetry/installation/installer.py:235 in _do_install
      233│             )
      234│ 
    → 235│             ops = solver.solve(use_latest=self._whitelist)
      236│         else:
      237│             self._io.write_line("Installing dependencies from lock file")

  1  ~/.poetry/lib/poetry/puzzle/solver.py:65 in solve
       63│         with self._provider.progress():
       64│             start = time.time()
    →  65│             packages, depths = self._solve(use_latest=use_latest)
       66│             end = time.time()
       67│ 

  SolverProblemError

  The current project's Python requirement (2.7.5) is not compatible with some of the required packages Python requirement:
    - jinja2 requires Python >=3.6, so it will not be satisfied for Python 2.7.5
  
  Because no versions of jinja2 match >3.0.1,<4.0.0
   and jinja2 (3.0.1) requires Python >=3.6, jinja2 is forbidden.
  So, because test-project depends on Jinja2 (^3.0.1), version solving failed.

  at ~/.poetry/lib/poetry/puzzle/solver.py:241 in _solve
      237│             packages = result.packages
      238│         except OverrideNeeded as e:
      239│             return self.solve_in_compatibility_mode(e.overrides, use_latest=use_latest)
      240│         except SolveFailure as e:
    → 241│             raise SolverProblemError(e)
      242│ 
      243│         results = dict(
      244│             depth_first_search(
      245│                 PackageNode(self._package, packages), aggregate_package_nodes

  • Check your dependencies Python requirement: The Python requirement can be specified via the `python` or `markers` properties
    
    For jinja2, a possible solution would be to set the `python` property to "<empty>"

    https://python-poetry.org/docs/dependency-specification/#python-restricted-dependencies,
    https://python-poetry.org/docs/dependency-specification/#using-environment-markers

I've tried the following variations on the --python flag in poetry init, none of which helped:

--python '2.7'
--python '^2.7'
--python '^2.7.5'
--python '~2.7'
--python '~2.7.5'

poetry add Jinja2==2.11.3 does work, but it would be nice if I didn't have to specify 😄

@sweetgiorni sweetgiorni added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Jun 10, 2021
@finswimmer finswimmer added the area/solver Related to the dependency resolver label Jun 18, 2021
@finswimmer
Copy link
Member

Hello @sweetgiorni,

I think this is a duplicate of #3901. Feel free to leave a comment if you disagree.

fin swimmer

@abn abn removed the status/triage This issue needs to be triaged label Mar 3, 2022
Copy link

github-actions bot commented Mar 2, 2024

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/solver Related to the dependency resolver kind/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

3 participants