E:\Anaconda3\envs\hanlp\lib\site-packages\torch\cuda\__init__.py:51: FutureWarning: The pynvml package is deprecated. Please install nvidia-ml-py instead. If you did not install pynvml directly, please report this to the maintainers of the package that installed pynvml for you.
import pynvml # type: ignore[import]
Failed to load https://file.hankcs.com/hanlp/ner/ner_bert_base_msra_20211227_114712.zip
E:\Anaconda3\envs\hanlp\lib\site-packages\hanlp\utils\component_util.py:137: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
from pkg_resources import parse_version
If the problem persists, please submit an issue to https://github.com/hankcs/HanLP/issues/new?labels=bug&template=bug_report.md
When reporting an issue, make sure to paste the FULL ERROR LOG below.
================================ERROR LOG BEGINS================================
OS: Windows-10-10.0.26100-SP0
Python: 3.10.18
PyTorch: 2.1.2+cpu
TensorFlow: 2.13.1
HanLP: 2.1.2
Traceback (most recent call last):
File "C:\Users\shark\PycharmProjects\PythonProject\main.py", line 7, in <module>
HanLP = hanlp.load(hanlp.pretrained.ner.MSRA_NER_BERT_BASE_ZH)
File "E:\Anaconda3\envs\hanlp\lib\site-packages\hanlp\__init__.py", line 43, in load
return load_from_meta_file(save_dir, 'meta.json', verbose=verbose, **kwargs)
File "E:\Anaconda3\envs\hanlp\lib\site-packages\hanlp\utils\component_util.py", line 188, in load_from_meta_file
raise e from None
File "E:\Anaconda3\envs\hanlp\lib\site-packages\hanlp\utils\component_util.py", line 106, in load_from_meta_file
obj.load(save_dir, verbose=verbose, **kwargs)
File "E:\Anaconda3\envs\hanlp\lib\site-packages\hanlp\common\keras_component.py", line 215, in load
self.build(**merge_dict(self.config, training=False, logger=logger, **kwargs, overwrite=True, inplace=True))
File "E:\Anaconda3\envs\hanlp\lib\site-packages\hanlp\common\keras_component.py", line 225, in build
self.model = self.build_model(**merge_dict(self.config, training=kwargs.get('training', None),
File "E:\Anaconda3\envs\hanlp\lib\site-packages\hanlp\components\taggers\transformers\transformer_tagger_tf.py", line 34, in build_model
model, tokenizer = build_transformer(transformer, max_seq_length, len(self.transform.tag_vocab), tagging=True)
File "E:\Anaconda3\envs\hanlp\lib\site-packages\hanlp\layers\transformers\loader_tf.py", line 14, in build_transformer
l_bert = TFAutoModel.from_pretrained(transformer)
File "E:\Anaconda3\envs\hanlp\lib\site-packages\transformers\models\auto\auto_factory.py", line 600, in from_pretrained
return model_class.from_pretrained(
File "E:\Anaconda3\envs\hanlp\lib\site-packages\transformers\modeling_tf_utils.py", line 2964, in from_pretrained
return load_pytorch_state_dict_in_tf2_model(
File "E:\Anaconda3\envs\hanlp\lib\site-packages\transformers\modeling_tf_pytorch_utils.py", line 333, in load_pytorch_state_dict_in_tf2_model
for key in pt_state_dict:
TypeError: 'builtins.safe_open' object is not iterable
=================================ERROR LOG ENDS=================================
pip list
Package Version
---------------------------- ---------
absl-py 2.3.1
astunparse 1.6.3
cachetools 6.2.1
certifi 2025.10.5
charset-normalizer 3.4.3
colorama 0.4.6
fasttext-wheel 0.9.2
filelock 3.20.0
flatbuffers 25.9.23
fsspec 2025.9.0
gast 0.4.0
google-auth 2.41.1
google-auth-oauthlib 1.0.0
google-pasta 0.2.0
grpcio 1.74.0
h5py 3.14.0
hanlp 2.1.2
hanlp_common 0.0.23
hanlp_downloader 0.0.25
hanlp_trie 0.0.5
huggingface-hub 0.35.3
idna 3.11
Jinja2 3.1.6
keras 2.13.1
libclang 18.1.1
Markdown 3.9
MarkupSafe 3.0.3
mpmath 1.3.0
networkx 3.4.2
numpy 1.24.3
nvidia-ml-py 13.580.82
oauthlib 3.3.1
opt_einsum 3.4.0
packaging 25.0
Penman 1.2.1
perin_parser 0.0.19
phrasetree 0.0.9
pip 25.2
protobuf 4.25.8
pyasn1 0.6.1
pyasn1_modules 0.4.2
pybind11 3.0.1
pynvml 13.0.1
PyYAML 6.0.3
regex 2025.9.18
requests 2.32.5
requests-oauthlib 2.0.0
rsa 4.9.1
safetensors 0.6.2
scipy 1.15.3
sentencepiece 0.2.1
setuptools 80.9.0
six 1.17.0
sympy 1.14.0
tensorboard 2.13.0
tensorboard-data-server 0.7.2
tensorflow 2.13.1
tensorflow-estimator 2.13.0
tensorflow-intel 2.13.1
tensorflow-io-gcs-filesystem 0.31.0
termcolor 3.1.0
tokenizers 0.22.1
toposort 1.5
torch 2.1.2
tqdm 4.67.1
transformers 4.57.0
typing_extensions 4.5.0
urllib3 2.5.0
Werkzeug 3.1.3
wheel 0.45.1
wrapt 1.17.3
Describe the bug
When use
pip install hanlp[full]to install on a Python 3.10 environment, pip installs a torch==2.1.2 and transformers==4.57.0(latest version).Transformers 4.57.0 is incompatible with torch 2.1.2.
We need to manually downgrade transformers version to 4.54.1 or lower.
Code to reproduce the issue
Provide a reproducible test case that is the bare minimum necessary to generate the problem.
Describe the current behavior
transformers error occured.
Expected behavior
Run code successfully.
System information
Other info / logs