Pylint error: 'optparse.OptionValueError: option spelling-dict: invalid value: 'en_US', should be in ['']'

Pylint error: 'optparse.OptionValueError: option spelling-dict: invalid value: 'en_US', should be in ['']'

当 运行 与 pylint 相关的任何内容时 - MINGW64-bash-CLI on Windows 10 中的命令,例如

pylint src/packages/ics/plugins/

或者只是为了了解版本

pylint -version

我总是得到同样的错误:

Traceback (most recent call last):
  File "C:\Users\username\.pyenv\pyenv-win\versions.9.4\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\username\.pyenv\pyenv-win\versions.9.4\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\username\Projects\proj-venv\Scripts\pylint.exe\__main__.py", line 7, in <module>
  File "c:\users\username\projects\proj-venv\lib\site-packages\pylint\__init__.py", line 24, in run_pylint
    PylintRun(sys.argv[1:])
  File "c:\users\username\projects\proj-venv\lib\site-packages\pylint\lint\run.py", line 333, in __init__
    linter.load_config_file()
  File "c:\users\username\projects\proj-venv\lib\site-packages\pylint\config\option_manager_mixin.py", line 315, in load_config_file
    self.global_set_option(option, value)
  File "c:\users\username\projects\proj-venv\lib\site-packages\pylint\config\option_manager_mixin.py", line 186, in global_set_option
    self._all_options[opt].set_option(opt, value)
  File "c:\users\username\projects\proj-venv\lib\site-packages\pylint\config\options_provider_mixin.py", line 54, in set_option
    value = _validate(value, optdict, optname)
  File "c:\users\username\projects\proj-venv\lib\site-packages\pylint\config\option.py", line 115, in _validate
    return _call_validator(_type, optdict, name, value)
  File "c:\users\username\projects\proj-venv\lib\site-packages\pylint\config\option.py", line 96, in _call_validator
    return VALIDATORS[opttype](optdict, option, value)
  File "c:\users\username\projects\proj-venv\lib\site-packages\pylint\config\option.py", line 83, in <lambda>
    "choice": lambda opt, name, value: _choice_validator(opt["choices"], name, value),
  File "c:\users\username\projects\proj-venv\lib\site-packages\pylint\config\option.py", line 31, in _choice_validator
    raise optparse.OptionValueError(msg % (name, value, choices))
optparse.OptionValueError: option spelling-dict: invalid value: 'en_US', should be in ['']

看来错误与系统语言环境有关'en_US'.


PS: 尝试按照建议将 pylint 升级到最新版本

它仍然失败并出现同样的错误:

$ pip install pylint -U
Requirement already satisfied: pylint in c:\users\andreas.luckert\projects\proj-venv\lib\site-packages (2.9.0)
Collecting pylint
  Downloading pylint-2.11.1-py3-none-any.whl (392 kB)
     |████████████████████████████████| 392 kB 6.4 MB/s
Requirement already satisfied: toml>=0.7.1 in c:\users\andreas.luckert\projects\proj-venv\lib\site-packages (from pylint) (0.10.2)
Collecting astroid<2.9,>=2.8.0
  Downloading astroid-2.8.0-py3-none-any.whl (242 kB)
     |████████████████████████████████| 242 kB 6.4 MB/s
Requirement already satisfied: mccabe<0.7,>=0.6 in c:\users\andreas.luckert\projects\proj-venv\lib\site-packages (from pylint) (0.6.1)
Requirement already satisfied: isort<6,>=4.2.5 in c:\users\andreas.luckert\projects\proj-venv\lib\site-packages (from pylint) (5.9.1)
Collecting typing-extensions>=3.10.0
  Downloading typing_extensions-3.10.0.2-py3-none-any.whl (26 kB)
Requirement already satisfied: colorama in c:\users\andreas.luckert\projects\proj-venv\lib\site-packages (from pylint) (0.4.4)
Collecting platformdirs>=2.2.0
  Downloading platformdirs-2.4.0-py3-none-any.whl (14 kB)
Requirement already satisfied: setuptools>=20.0 in c:\users\andreas.luckert\projects\proj-venv\lib\site-packages (from astroid<2.9,>=2.8.0->pylint) (49.2.1)
Requirement already satisfied: lazy-object-proxy>=1.4.0 in c:\users\andreas.luckert\projects\proj-venv\lib\site-packages (from astroid<2.9,>=2.8.0->pylint) (1.6.0)
Requirement already satisfied: wrapt<1.13,>=1.11 in c:\users\andreas.luckert\projects\proj-venv\lib\site-packages (from astroid<2.9,>=2.8.0->pylint) (1.12.1)
Installing collected packages: typing-extensions, platformdirs, astroid, pylint
  Attempting uninstall: typing-extensions
    Found existing installation: typing-extensions 3.7.4.3
    Uninstalling typing-extensions-3.7.4.3:
      Successfully uninstalled typing-extensions-3.7.4.3
  Attempting uninstall: astroid
    Found existing installation: astroid 2.6.3.dev0
    Uninstalling astroid-2.6.3.dev0:
      Successfully uninstalled astroid-2.6.3.dev0
  Attempting uninstall: pylint
    Found existing installation: pylint 2.9.0
    Uninstalling pylint-2.9.0:
      Successfully uninstalled pylint-2.9.0
Successfully installed astroid-2.8.0 platformdirs-2.4.0 pylint-2.11.1 typing-extensions-3.10.0.2


$ pylint --version
PYLINTHOME is now 'C:\Users\andreas.luckert\AppData\Local\pylint\pylint\Cache' but obsolescent 'C:\Users\andreas.luckert\.pylint.d' is found; you can safely remove the latter
pylint 2.11.1
astroid 2.8.0
Python 3.9.4 (tags/v3.9.4:1f2e308, Apr  6 2021, 13:40:21) [MSC v.1928 64 bit (AMD64)]


$ pylint src/packages/ics/plugins/
Traceback (most recent call last):
  File "C:\Users\andreas.luckert\.pyenv\pyenv-win\versions.9.4\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\andreas.luckert\.pyenv\pyenv-win\versions.9.4\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\andreas.luckert\Projects\proj-venv\Scripts\pylint.exe\__main__.py", line 7, in <module>
  File "C:\users\andreas.luckert\projects\proj-venv\lib\site-packages\pylint\__init__.py", line 24, in run_pylint
    PylintRun(sys.argv[1:])
  File "C:\users\andreas.luckert\projects\proj-venv\lib\site-packages\pylint\lint\run.py", line 324, in __init__
    linter.load_config_file()
  File "C:\users\andreas.luckert\projects\proj-venv\lib\site-packages\pylint\config\option_manager_mixin.py", line 321, in load_config_file     
    self.global_set_option(option, value)
  File "C:\users\andreas.luckert\projects\proj-venv\lib\site-packages\pylint\config\option_manager_mixin.py", line 189, in global_set_option    
    self._all_options[opt].set_option(opt, value)
  File "C:\users\andreas.luckert\projects\proj-venv\lib\site-packages\pylint\config\options_provider_mixin.py", line 54, in set_option
    value = _validate(value, optdict, optname)
  File "C:\users\andreas.luckert\projects\proj-venv\lib\site-packages\pylint\config\option.py", line 115, in _validate
    return _call_validator(_type, optdict, name, value)
  File "C:\users\andreas.luckert\projects\proj-venv\lib\site-packages\pylint\config\option.py", line 96, in _call_validator
    return VALIDATORS[opttype](optdict, option, value)
  File "C:\users\andreas.luckert\projects\proj-venv\lib\site-packages\pylint\config\option.py", line 83, in <lambda>
    "choice": lambda opt, name, value: _choice_validator(opt["choices"], name, value),
  File "C:\users\andreas.luckert\projects\proj-venv\lib\site-packages\pylint\config\option.py", line 31, in _choice_validator
    raise optparse.OptionValueError(msg % (name, value, choices))
optparse.OptionValueError: option spelling-dict: invalid value: 'en_US', should be in ['']

我是 pylint 维护者。您可以使用 pip install pylint -U 升级到最新的 pylint 并检查问题是否仍然存在?如果是这样,那肯定是 pylint 的问题。您可以在 pylint issue tracker 中提出问题,以便它得到修复。

可以在所有详细信息中找到解决方案 here

简而言之:

pip install pyenchant

已解决。

我通过brew install enchant

解决