升级pdm到2.20.0后,执行pdm add --dev mypy时报错了:
INFO: Adding group dev to lockfile
Adding packages to dev dev-dependencies: pytest, pdm, ruff, click, mypy
⠋ 0:00:00 Resolving dependencies
See /Users/mac10.12/Library/Logs/pdm/pdm-lock-aew5ui_n.log for detailed debug log.
[TypeError]: type 'AbstractProvider' is not subscriptable
WARNING: Add '-v' to see the detailed traceback
根据错误提示,打开/Users/mac10.12/Library/Logs/pdm/pdm-lock-aew5ui_n.log文件,发现报错的是:
pdm.termui: Error occurs
Traceback (most recent call last):File "/Users/mac10.12/.local/pipx/venvs/pdm/lib/python3.11/site-packages/pdm/termui.py", line 260, in loggingyield loggerFile "/Users/mac10.12/.local/pipx/venvs/pdm/lib/python3.11/site-packages/pdm/cli/actions.py", line 122, in do_lockresolver = resolver_class(^^^^^^^^^^^^^^^File "<string>", line 13, in __init__File "/Users/mac10.12/.local/pipx/venvs/pdm/lib/python3.11/site-packages/pdm/resolver/resolvelib.py", line 30, in __post_init__provider = self.project.get_provider(^^^^^^^^^^^^^^^^^^^^^^^^^^File "/Users/mac10.12/.local/pipx/venvs/pdm/lib/python3.11/site-packages/pdm/project/core.py", line 552, in get_providerfrom pdm.resolver.providers import get_providerFile "/Users/mac10.12/.local/pipx/venvs/pdm/lib/python3.11/site-packages/pdm/resolver/providers.py", line 49, in <module>class BaseProvider(AbstractProvider[Requirement, Candidate, str]):~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: type 'AbstractProvider' is not subscriptable
vi /Users/mac10.12/.local/pipx/venvs/pdm/lib/python3.11/site-packages/pdm/resolver/providers.py打开该文件,发现报错的是resolvelib库的AbstractProvider,猜测是该库没有升级到最新版导致的。
于是执行如下命令,升级该库,问题就解决了:
cd ~/.local/pipx/venvs/pdm # 注:我的pdm是用pipx安装的
source bin/activate
python -m pip install -U resolvelib
# Uninstalling resolvelib-1.0.1
# Successfully installed resolvelib-1.1.0
deactivate
cd -
pdm add --dev ruff