使用 Poetry 安装 SQLAlchemy 会导致 AttributeErrorr

Installing SQLAlchemy with Poetry causes an AttributeErrorr

用pip安装时,pip install sqlalchemy一切正常

使用 poetry 安装时出现错误

➜  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

尝试升级诗歌本身:pip install -U poetry。为我解决了 SQLAlchemy 问题。

如果你使用

诗添加sqlalchemy=1.4.22

这将解决您的问题

尝试 poetry self update,然后 poetry update

我试过 poetry self update 本身对我来说失败了,错误说:

ModuleNotFoundError: No module named 'poetry.console'

Whosebug answer 到一个不同的问题,我了解到我使用旧版本安装了诗歌,现在已弃用 get-poetry.py

所以我卸载了诗歌:

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

python get-poetry --uninstall

然后根据 official installation instructions 使用较新的 install-poetry.py 重新安装它。

这终于让原来的 AttributeError 消失了。

这里也一样,好像是最近才出现的问题。 好消息是“诗歌自更新”修复了这个问题

将诗歌升级到 1.1.8 可能会解决问题。

例如使用 poetry self update(相关 docs

也查看相关诗歌问题:

https://github.com/python-poetry/poetry/issues/4410#issuecomment-902144234