hankcs/HanLP · error · ModuleNotFoundError
Some modules ({e.name} etc.) required by this model are miss
Error message
Some modules ({e.name} etc.) required by this model are missing. Please install the full version:
pip install hanlp[full] -U What it means
While loading a model, one of its imports (transformers, a TF backend, an optional tokenizer, etc.) raised ModuleNotFoundError. Rather than surfacing the raw import error, HanLP tells you the minimal install is missing optional dependencies and suggests pip install hanlp[full] -U. When debugging is enabled the original error is re-raised unchanged.
Source
Thrown at hanlp/utils/component_util.py:115
assert cls, f'{meta_filename} doesn\'t contain classpath field'
try:
obj: Component = object_from_classpath(cls)
if hasattr(obj, 'load'):
if transform_only:
# noinspection PyUnresolvedReferences
obj.load_transform(save_dir)
else:
if os.path.isfile(os.path.join(save_dir, 'config.json')):
obj.load(save_dir, verbose=verbose, **kwargs)
else:
obj.load(metapath, **kwargs)
obj.config['load_path'] = load_path
return obj
except ModuleNotFoundError as e:
if isdebugging():
raise e from None
else:
raise ModuleNotFoundError(
f'Some modules ({e.name} etc.) required by this model are missing. Please install the full version:'
'\n\n\tpip install hanlp[full] -U') from None
except ValueError as e:
if e.args and isinstance(e.args[0], str) and 'Internet connection' in e.args[0]:
raise ConnectionError(
'Hugging Face 🤗 Transformers failed to download because your Internet connection is either off or bad.\n'
'See https://hanlp.hankcs.com/docs/install.html#server-without-internet for solutions.') \
from None
raise e from None
except Exception as e:
# Some users often install an incompatible tf and put the blame on HanLP. Teach them the basics.
try:
you_installed_wrong_versions, extras = check_version_conflicts(extras=('full',) if tf_model else None)
except Exception as check_e:
you_installed_wrong_versions, extras = None, None
if you_installed_wrong_versions:
raise version.NotCompatible(you_installed_wrong_versions + '\nPlease reinstall HanLP in the proper way:' +
'\n\n\tpip install --upgrade hanlp' + (View on GitHub (pinned to ddb1299bdd)
Solutions
- Run pip install 'hanlp[full]' -U (quote the extras in zsh).
- If you want a lean install, install just the missing module named in the message (e.g. pip install transformers) — but [full] is the supported combination.
- Set a debug flag (HANLP_DEBUG/isdebugging) if you need the original traceback to find which import failed.
Example fix
# before pip install hanlp # after pip install 'hanlp[full]' -U
Defensive patterns
Strategy: try-catch
Validate before calling
try:
import transformers # or the module your model needs
except ModuleNotFoundError:
raise SystemExit('pip install "hanlp[full]" -U') Try / catch
try:
model = hanlp.load(mid)
except ModuleNotFoundError as e:
if 'hanlp[full]' in str(e):
subprocess.run([sys.executable, '-m', 'pip', 'install', 'hanlp[full]', '-U'])
model = hanlp.load(mid)
else:
raise Prevention
- Install hanlp[full] up front in Dockerfiles and requirements.txt.
- Pin the extras in your dependency manifest so lean installs cannot ship.
When it happens
Trigger: Calling hanlp.load() on a transformer-backed or TF model with only the base hanlp package installed; e.name in the message tells you exactly which module is missing.
Common situations: Installing plain 'pip install hanlp' instead of hanlp[full]; stripped-down Docker images; upgrading hanlp but not its extras; mixing pip/conda envs so a dependency silently disappears.
Related errors
- Got average f{average}, expected one of None, 'token', or 'b
- alpha must be float, list of float, or torch.FloatTensor, {}
- Only supports floating point dtypes.
- Does not support dtype " + str(dtype)
- activation must be callable: type={}
AI-assisted analysis of hankcs/HanLP@ddb1299bdd (2026-08-27).
Data as JSON: /api/errors/91c9b02b0ab3d24b.
Report an issue: GitHub.