关于Python 3.10在使用百度飞桨 NLP 时import paddlenlp 报错 ModuleNotFoundError: No module named ‘seqeval‘ 的解决办法

版本信息:

Python :            3.10.9  (原打算用3.11.1版本,后来发现飞桨最高支持到3.10版本)

paddlepaddle:   2.4.1

paddlenlp:         2.4.1 (最新版是2.5.0,由于一直报错,降级到2.4.1)

seqeval:            1.2.2

测试过程:

准备学习一下paddlenlp 于是按照官方的说明进行安装,使用官方提供的代码进行测试,测试代码:

 信息抽取
from pprint import pprint
from paddlenlp import Taskflow 
schema = ['时间', '选手', '赛事名称'] # Define the schema for entity extraction 
ie = Taskflow('information_extraction', schema=schema) 
pprint(ie("2月8日上午北京冬奥会自由式滑雪女子大跳台决赛中中国选手谷爱凌以188.25分获得金牌!"))

如果正常执行,应该会输出下面信息:

[{'时间': [{'end': 6,
          'probability': 0.9857378532924486,
          'start': 0,
          'text': '2月8日上午'}],
  '赛事名称': [{'end': 23,
            'probability': 0.8503089953268272,
            'start': 6,
            'text': '北京冬奥会自由式滑雪女子大跳台决赛'}],
  '选手': [{'end': 31,
          'probability': 0.8981548639781138,
          'start': 28,
          'text': '谷爱凌'}]}]

错误信息:

但是事情并灭有很顺利,直接报错了,错误提示信息如下:

E:\pytodo\venv\lib\site-packages\_distutils_hack\__init__.py:33: UserWarning: Setuptools is replacing distutils.
  warnings.warn("Setuptools is replacing distutils.")
Traceback (most recent call last):
  File "e:\pytodo\test01.py", line 4, in 
    from paddlenlp import Taskflow
  File "E:\pytodo\venv\lib\site-packages\paddlenlp\__init__.py", line 30, in 
  File "E:\pytodo\venv\lib\site-packages\paddlenlp\metrics\__init__.py", line 16, in 
    from .chunk import ChunkEvaluator
  File "E:\pytodo\venv\lib\site-packages\paddlenlp\metrics\chunk.py", line 20, in 
    from seqeval.metrics.sequence_labeling import get_entities
ModuleNotFoundError: No module named 'seqeval'

根据提示,重新手动安装“seqeval”库,pip install seqeval ,安装默认最新版本的1.2.2 ,安装过程很顺利,也没有错误,但是再次运行,还是包同样错误。

查了一下原因,根据github的提示,应该是 seqeval 要安装1.2.1 版本的,于是手动进行安装。 

[已解决]ModuleNotFoundError: No module named 'jieba' or 'seqeval' · Issue #2340 · PaddlePaddle/PaddleNLP (github.com)

然而,pip install seqeval ==1.2.1 进行安装,有报错了……

venv) PS E:\pytodo> pip install seqeval==1.2.1
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/, https://pypi.tuna.tsinghua.edu.cn/simple/, https://pypi.douban.com/simple/, https://mirrors.ustc.edu.cn/pypi/
Collecting seqeval==1.2.1
  Using cached https://pypi.doubanio.com/packages/c4/47/f85f522f1f2532ca650474088e4024a9f52d524379bff058eaadf53cb663/seqeval-1.2.1.tar.gz (43 kB)
  Preparing metadata (setup.py) ... done
Collecting numpy==1.19.2
  Using cached https://pypi.doubanio.com/packages/bf/e8/15aea783ea72e2d4e51e3ec365e8dc4a1a32c9e5eb3a6d695b0d58e67cdd/numpy-1.19.2.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
  ╰─> [257 lines of output]
      Running from numpy source directory.
      setup.py:470: UserWarning: Unrecognized setuptools command, proceeding with generating Cython sources and expanding templates
        run_build = parse_setuppy_commands()
      Processing numpy/random\_bounded_integers.pxd.in
      Processing numpy/random\bit_generator.pyx
      Processing numpy/random\mtrand.pyx
      Processing numpy/random\_bounded_integers.pyx.in
      Processing numpy/random\_common.pyx
      Processing numpy/random\_generator.pyx
      Processing numpy/random\_mt19937.pyx
      Processing numpy/random\_pcg64.pyx
      Processing numpy/random\_philox.pyx
      Processing numpy/random\_sfc64.pyx
      Cythonizing sources
      blas_opt_info:
      blas_mkl_info:
      No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
      customize MSVCCompiler
        libraries mkl_rt not found in ['E:\\pytodo\\venv\\lib', 'C:\\']
        NOT AVAILABLE

      blis_info:
        libraries blis not found in ['E:\\pytodo\\venv\\lib', 'C:\\']
        NOT AVAILABLE

      openblas_info:
        libraries openblas not found in ['E:\\pytodo\\venv\\lib', 'C:\\']
      get_default_fcompiler: matching types: '['gnu', 'intelv', 'absoft', 'compaqv', 'intelev', 'gnu95', 'g95', 'intelvem', 'intelem', 'flang']'
      customize GnuFCompiler
      Could not locate executable g77
      Could not locate executable f77
      customize IntelVisualFCompiler
      Could not locate executable ifort
      Could not locate executable ifl
      customize AbsoftFCompiler
      Could not locate executable f90
      customize CompaqVisualFCompiler
      Could not locate executable DF
      customize IntelItaniumVisualFCompiler
      Could not locate executable efl
      customize Gnu95FCompiler
      Could not locate executable gfortran
      Could not locate executable f95
      customize G95FCompiler
      Could not locate executable g95
      customize IntelEM64VisualFCompiler
      customize IntelEM64TFCompiler
      Could not locate executable efort
      Could not locate executable efc
      customize PGroupFlangCompiler
      Could not locate executable flang
      don't know how to compile Fortran code on platform 'nt'
        NOT AVAILABLE

      atlas_3_10_blas_threads_info:
      Setting PTATLAS=ATLAS
        libraries tatlas not found in ['E:\\pytodo\\venv\\lib', 'C:\\']
        NOT AVAILABLE

      atlas_3_10_blas_info:
        libraries satlas not found in ['E:\\pytodo\\venv\\lib', 'C:\\']
        NOT AVAILABLE

      atlas_blas_threads_info:
      Setting PTATLAS=ATLAS
        libraries ptf77blas,ptcblas,atlas not found in ['E:\\pytodo\\venv\\lib', 'C:\\']
        NOT AVAILABLE

      atlas_blas_info:
        libraries f77blas,cblas,atlas not found in ['E:\\pytodo\\venv\\lib', 'C:\\']
        NOT AVAILABLE

      accelerate_info:
        NOT AVAILABLE

      C:\Users\admin\AppData\Local\Temp\pip-install-_drm9w48\numpy_e4ace71c56d54bf7af156925b951ce98\numpy\distutils\system_info.py:1914: UserWarning:
          Optimized (vendor) Blas libraries are not found.
          Falls back to netlib Blas library which has worse performance.
          A better performance should be easily gained by switching
          Blas library.
        if self._calc_info(blas):
      blas_info:
        libraries blas not found in ['E:\\pytodo\\venv\\lib', 'C:\\']
        NOT AVAILABLE

      C:\Users\admin\AppData\Local\Temp\pip-install-_drm9w48\numpy_e4ace71c56d54bf7af156925b951ce98\numpy\distutils\system_info.py:1914: UserWarning:
          Blas (http://www.netlib.org/blas/) libraries not found.
          Directories to search for the libraries can be specified in the
          numpy/distutils/site.cfg file (section [blas]) or by setting
          the BLAS environment variable.
        if self._calc_info(blas):
      blas_src_info:
        NOT AVAILABLE

      C:\Users\admin\AppData\Local\Temp\pip-install-_drm9w48\numpy_e4ace71c56d54bf7af156925b951ce98\numpy\distutils\system_info.py:1914: UserWarning:
          Blas (http://www.netlib.org/blas/) sources not found.
          Directories to search for the sources can be specified in the
          numpy/distutils/site.cfg file (section [blas_src]) or by setting
          the BLAS_SRC environment variable.
        if self._calc_info(blas):
        NOT AVAILABLE

      non-existing path in 'numpy\\distutils': 'site.cfg'
      lapack_opt_info:
      lapack_mkl_info:
        libraries mkl_rt not found in ['E:\\pytodo\\venv\\lib', 'C:\\']
        NOT AVAILABLE

      openblas_lapack_info:
        libraries openblas not found in ['E:\\pytodo\\venv\\lib', 'C:\\']
        NOT AVAILABLE

      openblas_clapack_info:
        libraries openblas,lapack not found in ['E:\\pytodo\\venv\\lib', 'C:\\']
        NOT AVAILABLE

      flame_info:
        libraries flame not found in ['E:\\pytodo\\venv\\lib', 'C:\\']
        NOT AVAILABLE

      atlas_3_10_threads_info:
      Setting PTATLAS=ATLAS
        libraries lapack_atlas not found in E:\pytodo\venv\lib
        libraries tatlas,tatlas not found in E:\pytodo\venv\lib
        libraries lapack_atlas not found in C:\
        libraries tatlas,tatlas not found in C:\
      
        NOT AVAILABLE

      atlas_3_10_info:
        libraries lapack_atlas not found in E:\pytodo\venv\lib
        libraries satlas,satlas not found in E:\pytodo\venv\lib
        libraries lapack_atlas not found in C:\
        libraries satlas,satlas not found in C:\
      
        NOT AVAILABLE

      atlas_threads_info:
      Setting PTATLAS=ATLAS
        libraries lapack_atlas not found in E:\pytodo\venv\lib
        libraries ptf77blas,ptcblas,atlas not found in E:\pytodo\venv\lib
        libraries lapack_atlas not found in C:\
        libraries ptf77blas,ptcblas,atlas not found in C:\
      
        NOT AVAILABLE

      atlas_info:
        libraries lapack_atlas not found in E:\pytodo\venv\lib
        libraries f77blas,cblas,atlas not found in E:\pytodo\venv\lib
        libraries lapack_atlas not found in C:\
        libraries f77blas,cblas,atlas not found in C:\
      
        NOT AVAILABLE

      lapack_info:
        libraries lapack not found in ['E:\\pytodo\\venv\\lib', 'C:\\']
        NOT AVAILABLE

      C:\Users\admin\AppData\Local\Temp\pip-install-_drm9w48\numpy_e4ace71c56d54bf7af156925b951ce98\numpy\distutils\system_info.py:1748: UserWarning:
          Lapack (http://www.netlib.org/lapack/) libraries not found.
          Directories to search for the libraries can be specified in the
          numpy/distutils/site.cfg file (section [lapack]) or by setting
          the LAPACK environment variable.
        return getattr(self, '_calc_info_{}'.format(name))()
      lapack_src_info:
        NOT AVAILABLE

      C:\Users\admin\AppData\Local\Temp\pip-install-_drm9w48\numpy_e4ace71c56d54bf7af156925b951ce98\numpy\distutils\system_info.py:1748: UserWarning:
          Lapack (http://www.netlib.org/lapack/) sources not found.
          Directories to search for the sources can be specified in the
          numpy/distutils/site.cfg file (section [lapack_src]) or by setting
          the LAPACK_SRC environment variable.
        return getattr(self, '_calc_info_{}'.format(name))()
        NOT AVAILABLE

      numpy_linalg_lapack_lite:
        FOUND:
          language = c
          define_macros = [('HAVE_BLAS_ILP64', None), ('BLAS_SYMBOL_SUFFIX', '64_')]

      C:\Users\admin\AppData\Local\Temp\pip-build-env-0uexikep\overlay\Lib\site-packages\setuptools\_distutils\dist.py:275: UserWarning: Unknown distribution option: 'define_macros'
        warnings.warn(msg)
      running dist_info
      running build_src
      build_src
      building py_modules sources
      creating build
      creating build\src.win-amd64-3.10
      creating build\src.win-amd64-3.10\numpy
      creating build\src.win-amd64-3.10\numpy\distutils
      building library "npymath" sources
      Traceback (most recent call last):
        File "E:\pytodo\venv\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 351, in 
          main()
        File "E:\pytodo\venv\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 333, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "E:\pytodo\venv\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 152, in prepare_metadata_for_build_wheel
          return hook(metadata_directory, config_settings)
        File "C:\Users\admin\AppData\Local\Temp\pip-build-env-0uexikep\overlay\Lib\site-packages\setuptools\build_meta.py", line 157, in prepare_metadata_for_build_wheel
          self.run_setup()
        File "C:\Users\admin\AppData\Local\Temp\pip-build-env-0uexikep\overlay\Lib\site-packages\setuptools\build_meta.py", line 248, in run_setup
          super(_BuildMetaLegacyBackend,
        File "C:\Users\admin\AppData\Local\Temp\pip-build-env-0uexikep\overlay\Lib\site-packages\setuptools\build_meta.py", line 142, in run_setup
          exec(compile(code, __file__, 'exec'), locals())
        File "setup.py", line 499, in 
          setup_package()
        File "setup.py", line 491, in setup_package
          setup(**metadata)
        File "C:\Users\admin\AppData\Local\Temp\pip-install-_drm9w48\numpy_e4ace71c56d54bf7af156925b951ce98\numpy\distutils\core.py", line 169, in setup
          return old_setup(**new_attr)
        File "C:\Users\admin\AppData\Local\Temp\pip-build-env-0uexikep\overlay\Lib\site-packages\setuptools\__init__.py", line 165, in setup
          return distutils.core.setup(**attrs)
        File "C:\Users\admin\AppData\Local\Temp\pip-build-env-0uexikep\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 148, in setup
          dist.run_commands()
        File "C:\Users\admin\AppData\Local\Temp\pip-build-env-0uexikep\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 967, in run_commands
          self.run_command(cmd)
        File "C:\Users\admin\AppData\Local\Temp\pip-build-env-0uexikep\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 986, in run_command
          cmd_obj.run()
        File "C:\Users\admin\AppData\Local\Temp\pip-build-env-0uexikep\overlay\Lib\site-packages\setuptools\command\dist_info.py", line 31, in run
          egg_info.run()
        File "C:\Users\admin\AppData\Local\Temp\pip-install-_drm9w48\numpy_e4ace71c56d54bf7af156925b951ce98\numpy\distutils\command\egg_info.py", line 24, in run
          self.run_command("build_src")
        File "C:\Users\admin\AppData\Local\Temp\pip-build-env-0uexikep\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 313, in run_command
          self.distribution.run_command(command)
        File "C:\Users\admin\AppData\Local\Temp\pip-build-env-0uexikep\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 986, in run_command
          cmd_obj.run()
        File "C:\Users\admin\AppData\Local\Temp\pip-install-_drm9w48\numpy_e4ace71c56d54bf7af156925b951ce98\numpy\distutils\command\build_src.py", line 144, in run
          self.build_sources()
        File "C:\Users\admin\AppData\Local\Temp\pip-install-_drm9w48\numpy_e4ace71c56d54bf7af156925b951ce98\numpy\distutils\command\build_src.py", line 155, in build_sources
          self.build_library_sources(*libname_info)
        File "C:\Users\admin\AppData\Local\Temp\pip-install-_drm9w48\numpy_e4ace71c56d54bf7af156925b951ce98\numpy\distutils\command\build_src.py", line 288, in build_library_sources
          sources = self.generate_sources(sources, (lib_name, build_info))
        File "C:\Users\admin\AppData\Local\Temp\pip-install-_drm9w48\numpy_e4ace71c56d54bf7af156925b951ce98\numpy\distutils\command\build_src.py", line 378, in generate_sources
          source = func(extension, build_dir)
        File "numpy\core\setup.py", line 650, in get_mathlib_info
          st = config_cmd.try_link('int main(void) { return 0;}')
        File "C:\Users\admin\AppData\Local\Temp\pip-build-env-0uexikep\overlay\Lib\site-packages\setuptools\_distutils\command\config.py", line 243, in try_link
          self._link(body, headers, include_dirs,
        File "C:\Users\admin\AppData\Local\Temp\pip-install-_drm9w48\numpy_e4ace71c56d54bf7af156925b951ce98\numpy\distutils\command\config.py", line 161, in _link
          return self._wrap_method(old_config._link, lang,
        File "C:\Users\admin\AppData\Local\Temp\pip-install-_drm9w48\numpy_e4ace71c56d54bf7af156925b951ce98\numpy\distutils\command\config.py", line 95, in _wrap_method
          ret = mth(*((self,)+args))
        File "C:\Users\admin\AppData\Local\Temp\pip-build-env-0uexikep\overlay\Lib\site-packages\setuptools\_distutils\command\config.py", line 137, in _link
          (src, obj) = self._compile(body, headers, include_dirs, lang)
ls\command\config.py", line 104, in _compile
          src, obj = self._wrap_method(old_config._compile, lang,
        File "C:\Users\admin\AppData\Local\Temp\pip-install-_drm9w48\numpy_e4ace71c56d54bf7af156925b951ce98\numpy\distutils\command\config.py", line 95, in _wrap_method
          ret = mth(*((self,)+args))
        File "C:\Users\admin\AppData\Local\Temp\pip-build-env-0uexikep\overlay\Lib\site-packages\setuptools\_distutils\command\config.py", line 132, in _compile
          self.compiler.compile([src], include_dirs=include_dirs)
        File "C:\Users\admin\AppData\Local\Temp\pip-build-env-0uexikep\overlay\Lib\site-packages\setuptools\_distutils\_msvccompiler.py", line 401, in compile
          self.spawn(args)
          return super().spawn(cmd, env=env)
        File "C:\Users\admin\AppData\Local\Temp\pip-install-_drm9w48\numpy_e4ace71c56d54bf7af156925b951ce98\numpy\distutils\ccompiler.py", line 90, in 
          m = lambda self, *args, **kw: func(self, *args, **kw)
      TypeError: CCompiler_spawn() got an unexpected keyword argument 'env'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

经过一番查看,应该是1.2.1版本不支持python 3.10 版本,这下蒙了……难道要自己去编译源码?

解决办法:

于是去下载了1.2.1版本的源码回来,正准备编译一下呢,但是反过来一想,源码都有了,还编译啥!直接上源码!

于是把源码文件直接粘贴到site-packages文件夹里,然后再次执行代码……

E:\pytodo\venv\lib\site-packages\_distutils_hack\__init__.py:33: UserWarning: Setuptools is replacing distutils.
  warnings.warn("Setuptools is replacing distutils.")
E:\pytodo\venv\lib\site-packages\jieba\_compat.py:4: DeprecationWarning: the imp module is deprecated in favour of importlib and slated for removal in Python 3.12; see the module's documentation for alternative uses
  import imp
[2023-01-13 13:59:14,601] [    INFO] - Downloading model_state.pdparams from https://bj.bcebos.com/paddlenlp/taskflow/information_extraction/uie_base_v1.1/model_state.pdparams
100%|███████████████████████████████████████████████████████████████████████████████████████████████████| 450M/450M [10:15<00:00, 766kB/s]
[2023-01-13 14:09:32,557] [    INFO] - Downloading model_config.json from https://bj.bcebos.com/paddlenlp/taskflow/information_extraction/uie_base/model_config.json
100%|████████████████████████████████████████████████████████████████████████████████████████████████████| 377/377 [00:00<00:00, 45.0kB/s]
[2023-01-13 14:09:32,769] [    INFO] - Downloading vocab.txt from https://bj.bcebos.com/paddlenlp/taskflow/information_extraction/uie_base/vocab.txt
100%|███████████████████████████████████████████████████████████████████████████████████████████████████| 182k/182k [00:00<00:00, 543kB/s]
[2023-01-13 14:09:33,294] [    INFO] - Downloading special_tokens_map.json from https://bj.bcebos.com/paddlenlp/taskflow/information_extraction/uie_base/special_tokens_map.json
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████| 112/112 [00:00<00:00, 112kB/s]
[2023-01-13 14:09:33,446] [    INFO] - Downloading tokenizer_config.json from https://bj.bcebos.com/paddlenlp/taskflow/information_extraction/uie_base/tokenizer_config.json
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████| 172/172 [00:00<00:00, 172kB/s]
[2023-01-13 14:09:33,632] [    INFO] - loading configuration file C:\Users\fwrx\.paddlenlp\taskflow\information_extraction\uie-base\model_config.json
[2023-01-13 14:09:33,634] [    INFO] - Model config ErnieConfig {
  "architectures": [
    "UIE"
  ],
  "attention_probs_dropout_prob": 0.1,
  "enable_recompute": false,
  "fuse": false,
  "hidden_act": "gelu",
  "hidden_dropout_prob": 0.1,
  "hidden_size": 768,
  "initializer_range": 0.02,
  "intermediate_size": 3072,
  "layer_norm_eps": 1e-12,
  "max_position_embeddings": 2048,
  "model_type": "ernie",
  "num_attention_heads": 12,
  "num_hidden_layers": 12,
  "pad_token_id": 0,
  "paddlenlp_version": null,
  "pool_act": "tanh",
  "task_id": 0,
  "task_type_vocab_size": 3,
  "type_vocab_size": 4,
  "use_task_id": true,
  "vocab_size": 40000
}

[2023-01-13 14:09:33,643] [    INFO] - Configuration saved in C:\Users\fwrx\.paddlenlp\taskflow\information_extraction\uie-base\config.json[2023-01-13 14:09:56,586] [    INFO] - All model checkpoint weights were used when initializing UIE.

[2023-01-13 14:09:56,587] [    INFO] - All the weights of UIE were initialized from the model checkpoint at C:\Users\fwrx\.paddlenlp\taskflow\information_extraction\uie-base.
If your task is similar to the task the model of the checkpoint was trained on, you can already use UIE for predictions without further training.
[2023-01-13 14:09:56,590] [    INFO] - Converting to the inference model cost a little time.
[2023-01-13 14:10:20,229] [    INFO] - The inference model save in the path:C:\Users\fwrx\.paddlenlp\taskflow\information_extraction\uie-base\static\inference
[2023-01-13 14:10:25,183] [    INFO] - We are using  to load 'C:\Users\fwrx\.paddlenlp\taskflow\information_extraction\uie-base'.
[{'时间': [{'end': 6,
          'probability': 0.9857378532473966,
          'start': 0,
          'text': '2月8日上午'}],
  '赛事名称': [{'end': 23,
            'probability': 0.8503081103003893,
            'start': 6,
            'text': '北京冬奥会自由式滑雪女子大跳台决赛'}],
  '选手': [{'end': 31,
          'probability': 0.8981535684051067,
          'start': 28,
          'text': '谷爱凌'}]}]

看样子是首次运行代码,有下载了一些模型库等数据。

经过一会的运行之后,结果出来了!

Python 3.10版本可用的源码在这里:Python3.10版本可用的seqeval-1.2.1版本源码-Python文档类资源-CSDN文库

你可能感兴趣的:(自然语言处理,自然语言处理,paddlepaddle,人工智能,python,pip)