1. 問題
MapTR、mmcv、mmdetection3d などを使用しているときに、以下のエラーに遭遇した
text, _ = FormatCode(text, style_config=yapf_style, verify=True)
TypeError: FormatCode() got an unexpected keyword argument 'verify'
2. 環境
item | version |
---|---|
python | 3.8.20 |
matplotlib | 3.5.3 |
mmcv-full | 1.4.0 |
mmdet | 2.14.0 |
mmdet3d | 0.17.2 |
mmsegmentation | 0.14.1 |
yapf | 0.43.0 |
3. 対処法
3-1. mmcv のバージョン変更しても良い場合
以下の記事に解決策が書かれている。
3-2. mmcv (mmcv-full) のバージョンを維持したい場合
続きに対処法を記載していきます。
3-2-1. 原因調査
まず、以下の位置に原因たる行があることを確認しました。
text, _ = FormatCode(text, style_config=yapf_style, verify=True)
この FormatCode
というクラスは、 yapf
という python ライブラリのクラスであることがわかる。(以下を参照)
from yapf.yapflib.yapf_api import FormatCode
3-2-2. 対策
そこで、 yapf
のバージョンを変更することにした。
pip install yapf==0.40.1
Collecting yapf==0.40.1
Downloading yapf-0.40.1-py3-none-any.whl.metadata (35 kB)
Requirement already satisfied: importlib-metadata>=6.6.0 in /usr/local/lib/python3.8/site-packages (from yapf==0.40.1) (7.2.1)
Requirement already satisfied: platformdirs>=3.5.1 in /usr/local/lib/python3.8/site-packages (from yapf==0.40.1) (4.3.6)
Requirement already satisfied: tomli>=2.0.1 in /usr/local/lib/python3.8/site-packages (from yapf==0.40.1) (2.1.0)
Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.8/site-packages (from importlib-metadata>=6.6.0->yapf==0.40.1) (3.20.2)
Downloading yapf-0.40.1-py3-none-any.whl (250 kB)
Installing collected packages: yapf
Attempting uninstall: yapf
Found existing installation: yapf 0.43.0
Uninstalling yapf-0.43.0:
Successfully uninstalled yapf-0.43.0
Successfully installed yapf-0.40.1
上記の通り、yapf
のバージョンを 0.43.0
から 0.40.1
に変更したところ、問題が解決した。