{"record":{"id":"cc7c026da47fb679","repo":"hankcs/HanLP","slug":"your-python-command-needs-to-be-python2-not-vers","errorCode":null,"errorMessage":"Your python command needs to be Python2, not {version.strip()}. Try:\n\n\tln -sf \"$(which python2)\" \"$(which python)\"","messagePattern":"Your python command needs to be Python2, not (.+?)\\. Try:\n\n\tln -sf \"\\$\\(which python2\\)\" \"\\$\\(which python\\)\"","errorType":"exception","errorClass":"EnvironmentError","httpStatus":null,"severity":"error","filePath":"hanlp/datasets/srl/ontonotes5/_utils.py","lineNumber":410,"sourceCode":"        print(f'Converting CoNLL file {full_file} to json file {v5_json_file}')\n        labels, stats = convert_to_jsonlines(full_file, v5_json_file, language)\n        print('Labels:')\n        pprint(labels)\n        print('Statistics:')\n        pprint(stats)\n        conll12_json_file = f'{lang_dir}/{split}.{language}.conll12.jsonlines'\n        print(f'Applying CoNLL 12 official splits on {v5_json_file} to {conll12_json_file}')\n        id_file = get_resource(f'https://file.hankcs.com/research/emnlp2021/conll.cemantix.org.zip#2012/download/ids/'\n                               f'{language}/coref/{split}.id')\n        filter_data(v5_json_file, conll12_json_file, id_file)\n\n\ndef ensure_python_points_to_python2():\n    exitcode, out, version = get_exitcode_stdout_stderr('python --version')\n    if not version:\n        version = out\n    if not version.startswith('Python 2'):\n        raise EnvironmentError(f'Your python command needs to be Python2, not {version.strip()}. Try:\\n\\n\\t'\n                               'ln -sf \"$(which python2)\" \"$(which python)\"')\n\n\ndef make_gold_conll(ontonotes_path, language):\n    ensure_python_points_to_python2()\n    ontonotes_path = os.path.abspath(get_resource(ontonotes_path))\n    to_conll = get_resource(\n        'https://gist.githubusercontent.com/hankcs/46b9137016c769e4b6137104daf43a92/raw/66369de6c24b5ec47696ae307591f0d72c6f3f02/ontonotes_to_conll.sh')\n    to_conll = os.path.abspath(to_conll)\n    # shutil.rmtree(os.path.join(ontonotes_path, 'conll-2012'), ignore_errors=True)\n    with pushd(ontonotes_path):\n        try:\n            flash(f'Converting [blue]{language}[/blue] to CoNLL format, '\n                  f'this might take half an hour [blink][yellow]...[/yellow][/blink]')\n            run_cmd(f'bash {to_conll} {ontonotes_path} {language}')\n            flash('')\n        except RuntimeError as e:\n            flash(f'[red]Failed[/red] to convert {language} of {ontonotes_path} to CoNLL. See exceptions for detail')","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/datasets/srl/ontonotes5/_utils.py#L392-L428","documentation":"Building the gold CoNLL files for OntoNotes 5 uses the official LDC scripts, which are Python 2 only. ensure_python_points_to_python2 runs `python --version`; if it doesn't start with 'Python 2', it raises EnvironmentError with a suggested symlink fix because the pipeline depends on a python2 interpreter being reachable as `python`.","triggerScenarios":"Running make_gold_conll (or hanlp datasets preparation for srl/ontonotes5) on modern systems where `python` is Python 3; environments without python2 installed at all.","commonSituations":"Ubuntu 20.04+/Debian where python2 is not installed; conda/venv environments where python points to python3; CI images with only Python 3.","solutions":["Install python2 and make `python` resolve to it in that shell: sudo apt install python2 && ln -sf \"$(which python2)\" \"$(which python)\" (or use an alias/PATH shim only for the conversion step)","Activate an environment (conda create -n py2 python=2.7) where python is 2.x before running make_gold_conll","Alternatively download pre-converted OntoNotes _conll files instead of converting yourself"],"exampleFix":"# shell\nsudo apt-get install -y python2\nln -sf \"$(which python2)\" \"$(which python)\"\npython --version   # Python 2.7.x\npython -m hanlp ... # or your conversion script","handlingStrategy":"validation","validationCode":"import subprocess, shutil\nif shutil.which('python2') is None:\n    raise SystemExit('python2 required for OntoNotes conversion scripts; install it first')\nout = subprocess.run(['python', '--version'], capture_output=True, text=True)\nif not (out.stdout or out.stderr).startswith('Python 2'):\n    raise SystemExit(\"point 'python' at python2 for this step (see ln -sf suggestion)\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run OntoNotes conversion inside a dedicated python2 environment","Consider downloading pre-converted _conll files to skip python2 entirely"],"tags":["python","python2","environment","ontonotes","dependency"],"backgroundTag":"python-version-mismatch","analyzedSha":"ddb1299bddff079e447af52ec12549c50636bfa8","analyzedAt":"2026-08-27T03:36:54.287Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}