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

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

Closed
3 tasks done
bi1yeu opened this issue Oct 19, 2018 · 29 comments
Closed
3 tasks done
Labels
kind/bug Something isn't working as expected

Comments

@bi1yeu
Copy link

bi1yeu commented Oct 19, 2018

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

@bi1yeu
Copy link
Author

bi1yeu commented Oct 19, 2018

Update: When I use pyenv to explicitly set the local Python version to 3 (I tried both 3.6.5 and 3.7.0), I am able to add the jupyter package.

$ poetry new example
$ cd example
$ pyenv local 3.6.5
$ poetry add jupyter # installs fine

This fails with the same AttributeError as above if I instead use pyenv local 2.7.10.

I can install jupyter directly using pip and Python 2.7:

$ mkdir example
$ cd example
$ pyenv local 2.7.10
$ python -m pip install --upgrade pip
$ python -m pip install jupyter # installs fine

@sdispater
Copy link
Member

There was an issue when parsing some transitive markers. It has been fixed in commit 7761867

@sdispater sdispater added the kind/bug Something isn't working as expected label Oct 19, 2018
@sdispater
Copy link
Member

This has been fixed in the latest release.

@bi1yeu
Copy link
Author

bi1yeu commented Oct 22, 2018 via email

@flaviut
Copy link

flaviut commented Jul 11, 2019

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

@nc7s
Copy link

nc7s commented Aug 10, 2019

Got the same error with 0.12.17 & Python version 3.7.4; same prompt as @flaviut 's comment.

It seems to be create_nested_marker() missing EmptyConstraint when checking the type of constraint. Manual patching ~/.poetry/lib/poetry/packages/utils/utils.py to import poetry.semver.empty_constraint.EmptyConstraint and add it to check list said above solved the problem locally.

@agilgur5
Copy link

agilgur5 commented Sep 10, 2019

Also getting this error with Poetry 0.12.17. Can we re-open this issue?

@mwoyuan to which check (line #?) did you add EmptyConstraint? Maybe submit a PR if you were able to patch it?
EDIT: added EmptyConstraint import after line 9:

from poetry.semver import Version
from poetry.semver import VersionUnion
from poetry.semver.empty_constraint import EmptyConstraint  # this line is new

and a new if statement after line 206/207:

    elif isinstance(constraint, Version):
        marker = '{} == "{}"'.format(name, constraint.text)
    elif isinstance(constraint, EmptyConstraint):  # and this line
        marker = ''  # and this one
    else:

And now it seems to work ok

@laike9m
Copy link
Contributor

laike9m commented Feb 3, 2020

Met this issue on Poetry 1.0.3 + Python 3.7.4

@andreoliwa
Copy link

I'm having the same error on Poetry 1.0.9.

The package I'm trying (AuHau/toggl-cli) has:

python_requires = >=3.6.0, <3.9.0

This is my debug info, and a gist below with pyproject.toml and the full error log.

Poetry
Version: 1.0.9
Python:  3.8.3

Virtualenv
Python:         3.8.3
Implementation: CPython
Path:           /Users/wagneraugusto/Library/Caches/pypoetry/virtualenvs/toggl-cli-bug-t9z0mPRw-py3.8
Valid:          True

System
Platform: darwin
OS:       posix
Python:   /Users/wagneraugusto/.pyenv/versions/3.8.3

Poetry [AttributeError] 'EmptyConstraint' object has no attribute 'min'

@glencairn
Copy link
Contributor

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

@leikoilja
Copy link

leikoilja commented Mar 13, 2021

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

@Ver1Sus
Copy link

Ver1Sus commented Mar 26, 2021

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)

@pksol
Copy link

pksol commented Mar 31, 2021

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.

@gjedlicska
Copy link

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

@willfrey
Copy link
Contributor

willfrey commented Apr 2, 2021

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

@Ver1Sus
Copy link

Ver1Sus commented Apr 2, 2021

@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'

@dem1tris
Copy link

dem1tris commented Apr 2, 2021

#3862
Temporary workaround: pin pytest-randomly = "3.5.0"

@jamie--stewart
Copy link

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

@gatoniel
Copy link

gatoniel commented Apr 6, 2021

I encountered the same issue and the solution of @glencairn solved the problem. My poetry debug is:

Poetry
Version: 1.1.5
Python:  3.8.8

Virtualenv
Python:         3.8.8
Implementation: CPython
Path:           /home/netter/.cache/pypoetry/virtualenvs/stereographic-link-prediction-ra14Y8Aq-py3.8
Valid:          True

System
Platform: linux
OS:       posix
Python:   /home/netter/miniconda3

@dycw
Copy link

dycw commented Apr 7, 2021

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

@tony
Copy link
Contributor

tony commented Apr 11, 2021

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

via @pksol at #534 (comment)

poetry update gives me the EmptyConstraint error at Poetry 1.0.10

pyflakes gave me this via flake8

@tony
Copy link
Contributor

tony commented Apr 11, 2021

Follow up

If your issue in backports.functools_lru_cache:

Workaround: @pbzweihander's fix here helped me in pyproject.toml:

"backports.functools_lru_cache" = "!=1.6.2,!=1.6.3" # https://github.com/jaraco/backports.functools_lru_cache/pull/16

There is a PR to fix this here: jaraco/backports.functools_lru_cache#16

@mforbes
Copy link

mforbes commented May 7, 2021

I was having this error because of misinterpreting the docs with a constraint like python = ^2.7,^3.6 where the comma appears to mean logical and. Instead, I needed python = ^2.7 || ^3.6 as discussed in issue #2372.

@elicutler
Copy link

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

@mdengler
Copy link

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

I opened an issue for this specific error: #4410

@Mazyod
Copy link

Mazyod commented Aug 24, 2021

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)

@dsm0014
Copy link

dsm0014 commented Aug 24, 2021

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

@iXanthos
Copy link

This issue still persists at poetry 1.1.12. When running poetry add --dev pytest pytest-cov black isort flake8 bandit safety

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
kind/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests