hankcs/HanLP · error · RuntimeError
Conversion failed with code {code} for {src}. The err messag
Error message
Conversion failed with code {code} for {src}. The err message is:\n {err}\nDo you have java installed? Do you have enough memory? What it means
After running the Stanford Parser jar via subprocess to convert CTB trees, convert_to_dependency checks the process exit code. A non-zero code means java failed (missing JVM, wrong java version, or out-of-memory during conversion), and the collected stderr is included in the RuntimeError.
Source
Thrown at hanlp/datasets/parsing/loaders/_ctb_utils.py:103
sp_home = get_resource(sp_home)
# jar_path = get_resource(f'{sp_home}#stanford-parser.jar')
if ud:
jclass = 'edu.stanford.nlp.trees.international.pennchinese.UniversalChineseGrammaticalStructure' if language == 'zh' \
else 'edu.stanford.nlp.trees.ud.UniversalDependenciesConverter'
else:
jclass = 'edu.stanford.nlp.trees.international.pennchinese.ChineseGrammaticalStructure' if language == 'zh' \
else 'edu.stanford.nlp.trees.EnglishGrammaticalStructure'
cmd = f'java -cp {sp_home}/* {jclass} ' \
f'-treeFile {src}'
if conllx:
cmd += ' -conllx'
if not ud:
cmd += f' -basic -keepPunct'
code, out, err = get_exitcode_stdout_stderr(cmd)
with open(dst, 'w') as f:
f.write(out)
if code:
raise RuntimeError(f'Conversion failed with code {code} for {src}. The err message is:\n {err}\n'
f'Do you have java installed? Do you have enough memory?')
def clean_ctb_bracketed(ctb_root, out_root):
os.makedirs(out_root, exist_ok=True)
ctb_root = join(ctb_root, 'bracketed')
chtbs = _list_treebank_root(ctb_root)
timer = CountdownTimer(len(chtbs))
for f in chtbs:
with open(join(ctb_root, f), encoding='utf-8') as src, open(join(out_root, f + '.txt'), 'w',
encoding='utf-8') as out:
for line in src:
if not line.strip().startswith('<'):
out.write(line)
timer.log('Cleaning up CTB [blink][yellow]...[/yellow][/blink]', erase=False)
def _list_treebank_root(ctb_root):View on GitHub (pinned to ddb1299bdd)
Solutions
- Install a JDK/JRE (java -version must work) — Stanford Parser 4.2.0 needs Java 8+
- If it's an OOM, raise heap: export JAVA_OPTS or _JAVA_OPTIONS='-Xmx8g' and retry
- Check the err text in the message for the underlying java error and address it (version mismatch, corrupt download)
- Verify the Stanford Parser zip downloaded fully (re-download if corrupted)
Example fix
# shell sudo apt-get install -y openjdk-11-jre-headless export _JAVA_OPTIONS='-Xmx8g' python prepare_ctb.py
Defensive patterns
Strategy: try-catch
Validate before calling
import shutil
if shutil.which('java') is None:
raise SystemExit('java not found; install a JDK/JRE before conversion') Try / catch
try:
convert_to_dependency(src, dst, language='zh', version='4.2.0')
except RuntimeError as e:
msg = str(e)
if 'enough memory' in msg:
import os
os.environ['_JAVA_OPTIONS'] = '-Xmx8g'
convert_to_dependency(src, dst, language='zh', version='4.2.0')
else:
raise Prevention
- Pre-check `which java` and set -Xmx heap before batch conversions
- Run a small smoke conversion on one file before processing the full treebank
When it happens
Trigger: Running make_ctb_tasks/make_dep_conllx on a machine without java on PATH; java too old/new for the Stanford Parser jar; large treebank conversions exhausting heap (default JVM max heap).
Common situations: Fresh CI containers or slim Docker images without a JDK; converting full CTB9 where the parser needs several GB of heap.
Related errors
- Unsupported version {version}
- 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)
AI-assisted analysis of hankcs/HanLP@ddb1299bdd (2026-08-27).
Data as JSON: /api/errors/13d7954d1a74dc22.
Report an issue: GitHub.