poetry: Error when adding package: EmptyConstraint instance has no attribute 'min'

  • 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).

Issue

Hi! This is my first time attempting to use poetry. I created a new empty project with this command:

$ poetry new example

Then, from within the example directory, I attempt to add the jupyter package:

$ poetry add jupyter
Using version ^1.0 for jupyter

Updating dependencies
Resolving dependencies... (4.0s)

[AttributeError]
EmptyConstraint instance has no attribute 'min'

add [-D|--dev] [--git GIT] [--path PATH] [-E|--extras EXTRAS] [--optional] [--python PYTHON] [--platform PLATFORM] [--allow-prereleases] [--dry-run] [--] <name> (<name>)...

Verbose output is contained within the gist linked above. I am able to add other packages without apparent error. Happy to provide additional info.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 29 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I’m experiencing this same issue with Poetry 1.1.4 when trying to install certain packages. I was able to get around the issue following a similar approach that @bnoctis and @agilgur5 detailed above. However, for a more recent vendorized install, the file I had to modify was ~/.poetry/lib/poetry/_vendor/py3.8/poetry/core/packages/dependency.py (where python3.8 is my active interpreter).

Here’s a diff of the modifications I made, hopefully others find this useful:

diff --git a/tmp.py b/Users/user/.poetry/lib/poetry/_vendor/py3.8/poetry/core/packages/dependency.py
index e118794..6f97002 100644
--- a/tmp.py
+++ b/Users/user/.poetry/lib/poetry/_vendor/py3.8/poetry/core/packages/dependency.py
@@ -9,6 +9,7 @@ from poetry.core.semver import Version
 from poetry.core.semver import VersionConstraint
 from poetry.core.semver import VersionRange
 from poetry.core.semver import VersionUnion
+from poetry.core.semver import EmptyConstraint
 from poetry.core.semver import parse_constraint
 from poetry.core.version.markers import AnyMarker
 from poetry.core.version.markers import parse_marker
@@ -291,6 +292,8 @@ class Dependency(PackageSpecification):
                 name = "python_full_version"
 
             marker = '{} == "{}"'.format(name, constraint.text)
+        elif isinstance(constraint, EmptyConstraint):
+            marker = ''
         else:
             if constraint.min is not None:
                 min_name = name

System: MacOS Poetry: 1.1.4

I had to edit ~/.poetry/lib/poetry/_vendor/py3.8/poetry/core/version/markers.py

from poetry.core.packages.constraints.empty_constraint import EmptyConstraint

and line 281 in the definition of validate(self, environment), added:

if isinstance(self._constraint, EmptyConstraint):
    return True

Flip, tool me good 30 mins to fix it. MacOS M1, Poetry 1.1.5, Python 3.9.2 (darwin) Had to do both those fixes as mentioned above by @glencairn and @bnocti, @agilgur5

Met this issue on Poetry 1.0.3 + Python 3.7.4

https://github.com/python-poetry/poetry/issues/3862 Temporary workaround: pin pytest-randomly = "3.5.0"

Like @glencairn comment, but this works for me:

        elif constraint.is_empty():
            marker = ''

System: Ubuntu 20 Poetry: 1.0.1 Python: 2.7

P.S. Iam not sure, but this package was causing an error backports.functools-lru-cache (1.6.3)

I think there’s been a regression here; I get the same error with 0.12.16:

$ poetry -V
Poetry 0.12.16
$ poetry add jupyter
                                                   
[AttributeError]                    
'EmptyConstraint' object has no attribute 'min'  
                                                   
add [-D|--dev] [--git GIT] [--path PATH] [-E|--extras EXTRAS] [--optional] [--python PYTHON] [--platform PLATFORM] [--allow-prereleases] [--dry-run] [--] <name> (<name>)...

Encountered this issue with poetry version 1.1.7. In my experience, I can confirm updating to version 1.1.8 resolves this issue.

Thanks, @Ver1Sus! backports.functools-lru-cache was causing problems for me as well and fixating its version to 1.6.1 fixed it.

Tell me, how did you know that the problem was with this particular package? I’m wondering since it might happen again with another package.

I had to edit ~/.poetry/lib/poetry/_vendor/py3.8/poetry/core/version/markers.py

from poetry.core.packages.constraints.empty_constraint import EmptyConstraint

and line 281 in the definition of validate(self, environment), added:

if isinstance(self._constraint, EmptyConstraint):
    return True

Just to avoid the import in my case, I used not hasattr(self._constraint, "allows")

(Or update to version 1.1.8, it apparently fixed the issue)

I found @dem1tris’s solution to be helpful - I changed pytest-randomly = "^3.5" to "3.5.0".

I’m seeing the same issue as @glencairn identified:

  • macOs 11.0.1
  • poetry 1.1.15
  • python 3.8.7

The patch they identified has fixed my issue.

Can anyone guide me on how to identify the offending package? I think we may need to raise a fresh issue here as it seems like whatever causes this has not been resolved, or resurfaced

@pksol, I’m glad that the solution helped!

I ran poetry update -vvv with verbose, and poetry pointed out the problematic package:

PyPI: 8 packages found for backports.functools-lru-cache >=1.2.1
 1 packages found for backports.functools-lru-cache >=1.2.1
   1: Version solving took 40.500 seconds.
   1: Tried 1 solutions.

[AttributeError]
EmptyConstraint instance has no attribute 'min'

This is also happening due to a change in pytest-randomly, FWIW.

Same issue here, my poetry debug is

Poetry
Version: 1.1.5
Python:  3.8.8

Virtualenv
Python:         3.8.8
Implementation: CPython
Path:           /home/gergojedlicska/.cache/pypoetry/virtualenvs/prjectproject-kXrNwMJU-py3.8
Valid:          True

System
Platform: linux
OS:       posix
Python:   /home/gergojedlicska/.asdf/installs/python/3.8.8