Installing SQLAlchemy with Poetry causes an AttributeErrorr

Viewed 3409

When installing with pip, pip install sqlalchemy all is ok.

When installing with poetry I am getting the error

➜  backend poetry add sqlalchemy
Using version ^1.4.23 for SQLAlchemy

Updating dependencies
Resolving dependencies... (0.1s)

  AttributeError

  'EmptyConstraint' object has no attribute 'allows'

  at ~/.poetry/lib/poetry/_vendor/py3.8/poetry/core/version/markers.py:291 in validate
      287│
      288│         if self._name not in environment:
      289│             return True
      290│
    → 291│         return self._constraint.allows(self._parser(environment[self._name]))
      292│
      293│     def without_extras(self):  # type: () -> MarkerTypes
      294│         return self.exclude("extra")
      295│
➜  backend
6 Answers

Try poetry self update, then poetry update.

If you use

poetry add sqlalchemy=1.4.22

This will solve your problem

Try upgrading poetry itself: pip install -U poetry. Worked for me to resolve SQLAlchemy issue.

I tried fl_'s answer but poetry self update itself failed for me with an error saying:

ModuleNotFoundError: No module named 'poetry.console'

From a stackoverflow answer to a different question I learned that I had poetry installed using the older, now deprecated, get-poetry.py.

So I uninstalled poetry like so:

curl https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py > get-poetry

python get-poetry --uninstall

Then reinstalled it with the newer install-poetry.py as per official installation instructions.

This finally made the original AttributeError go away.

Same here, it seems to be a very recent problem. The good news is that "poetry self update" fixes the issue

Related