安装zero_shot_re遇numpy编译错误,寻求解决方案
问题:无法安装zero-shot-re模块,numpy==1.19.1编译失败
运行以下关系抽取代码时,出现ModuleNotFoundError: No module named 'zero_shot_re'错误:
from transformers import AutoTokenizer from zero_shot_re import RelTaggerModel, RelationExtractor model = RelTaggerModel.from_pretrained("fractalego/fewrel-zero-shot") tokenizer = AutoTokenizer.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad") relations = ['associated', 'interacts'] extractor = RelationExtractor(model, tokenizer, relations)
尝试执行pip install zero-shot-re安装模块时,遇到numpy==1.19.1编译失败,核心错误日志如下:
(biomedical-knowledge-graph-venv) C:\Users\User\Documents\GitHub\biomedical-knowledge-graph-nlp>pip install zero-shot-re Collecting zero-shot-re Using cached zero_shot_re-0.0.4-py3-none-any.whl (6.6 kB) Collecting numpy==1.19.1 (from zero-shot-re) Using cached numpy-1.19.1.zip (7.3 MB) Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... error error: subprocess-exited-with-error × Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [关键输出片段] Error compiling Cython file: ------------------------------------------------------------ ... self._bitgen.next_uint64 = &mt19937_uint64 ^ ------------------------------------------------------------ _mt19937.pyx:138:35: Cannot assign type 'uint64_t (*)(void *) except? -1 nogil' to 'uint64_t (*)(void *) noexcept nogil'. Exception values are incompatible. Suggest adding 'noexcept' to type 'uint64_t (void *) except? -1 nogil'. ... RuntimeError: Running cythonize failed! [end of output] error: metadata-generation-failed
已尝试以下操作但问题仍未解决:
pip install --upgrade pippip install --upgrade cythonpip install --upgrade setuptools wheelpip install --no-cache-dir -v numpy==1.19.1
解决方案
方案1:绕过numpy版本限制安装
numpy==1.19.1与Python3.10+兼容性较差,先安装适配当前Python的numpy版本,再忽略依赖安装zero-shot-re,最后补全必要依赖:
# 安装兼容当前Python的numpy版本 pip install numpy>=1.21 # 忽略依赖安装zero-shot-re pip install zero-shot-re --no-deps # 手动补全所需核心依赖 pip install transformers torch
方案2:从GitHub源码安装最新版
PyPI上的zero-shot-re旧版本绑定了过时的numpy依赖,直接从源码安装可避免版本冲突:
pip install git+https://github.com/fractalego/zero-shot-re.git
方案3:降级Python版本
若上述方案无效,可将Python降级至3.8或3.9版本(numpy==1.19.1对这两个版本支持更好),之后再执行pip install zero-shot-re即可正常安装。
内容的提问来源于stack exchange,提问作者Le Dinh Tuan
相关产品推荐
相关产品推荐

