本文介绍: 关于Python 3.10在使用百度飞桨 NLP 时 报错 ModuleNotFoundError: No module namedseqeval‘ 的解决办法

版本信息

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:pytodovenvlibsite-packages_distutils_hack__init__.py:33: UserWarning: Setuptools is replacing distutils.
  warnings.warn("Setuptools is replacing distutils.")
Traceback (most recent call last):
  File "e:pytodotest01.py", line 4, in <module&gt;
    from paddlenlp import Taskflow
  File "E:pytodovenvlibsite-packagespaddlenlp__init__.py", line 30, in <module&gt;
  File "E:pytodovenvlibsite-packagespaddlenlpmetrics__init__.py", line 16, in <module&gt;
    from .chunk import ChunkEvaluator
  File "E:pytodovenvlibsite-packagespaddlenlpmetricschunk.py", line 20, in <module&gt;
    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&gt; 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/randombit_generator.pyx
      Processing numpy/randommtrand.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:UsersadminAppDataLocalTemppip-install-_drm9w48numpy_e4ace71c56d54bf7af156925b951ce98numpydistutilssystem_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:UsersadminAppDataLocalTemppip-install-_drm9w48numpy_e4ace71c56d54bf7af156925b951ce98numpydistutilssystem_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:UsersadminAppDataLocalTemppip-install-_drm9w48numpy_e4ace71c56d54bf7af156925b951ce98numpydistutilssystem_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:pytodovenvlib
        libraries tatlas,tatlas not found in E:pytodovenvlib
        libraries lapack_atlas not found in C:
        libraries tatlas,tatlas not found in C:
      <class 'numpy.distutils.system_info.atlas_3_10_threads_info'>
        NOT AVAILABLE

      atlas_3_10_info:
        libraries lapack_atlas not found in E:pytodovenvlib
        libraries satlas,satlas not found in E:pytodovenvlib
        libraries lapack_atlas not found in C:
        libraries satlas,satlas not found in C:
      <class 'numpy.distutils.system_info.atlas_3_10_info'>
        NOT AVAILABLE

      atlas_threads_info:
      Setting PTATLAS=ATLAS
        libraries lapack_atlas not found in E:pytodovenvlib
        libraries ptf77blas,ptcblas,atlas not found in E:pytodovenvlib
        libraries lapack_atlas not found in C:
        libraries ptf77blas,ptcblas,atlas not found in C:
      <class 'numpy.distutils.system_info.atlas_threads_info'>
        NOT AVAILABLE

      atlas_info:
        libraries lapack_atlas not found in E:pytodovenvlib
        libraries f77blas,cblas,atlas not found in E:pytodovenvlib
        libraries lapack_atlas not found in C:
        libraries f77blas,cblas,atlas not found in C:
      <class 'numpy.distutils.system_info.atlas_info'>
        NOT AVAILABLE

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

      C:UsersadminAppDataLocalTemppip-install-_drm9w48numpy_e4ace71c56d54bf7af156925b951ce98numpydistutilssystem_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:UsersadminAppDataLocalTemppip-install-_drm9w48numpy_e4ace71c56d54bf7af156925b951ce98numpydistutilssystem_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:UsersadminAppDataLocalTemppip-build-env-0uexikepoverlayLibsite-packagessetuptools_distutilsdist.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 buildsrc.win-amd64-3.10
      creating buildsrc.win-amd64-3.10numpy
      creating buildsrc.win-amd64-3.10numpydistutils
      building library "npymath" sources
      Traceback (most recent call last):
        File "E:pytodovenvlibsite-packagespip_vendorpep517in_process_in_process.py", line 351, in <module>
          main()
        File "E:pytodovenvlibsite-packagespip_vendorpep517in_process_in_process.py", line 333, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "E:pytodovenvlibsite-packagespip_vendorpep517in_process_in_process.py", line 152, in prepare_metadata_for_build_wheel
          return hook(metadata_directory, config_settings)
        File "C:UsersadminAppDataLocalTemppip-build-env-0uexikepoverlayLibsite-packagessetuptoolsbuild_meta.py", line 157, in prepare_metadata_for_build_wheel
          self.run_setup()
        File "C:UsersadminAppDataLocalTemppip-build-env-0uexikepoverlayLibsite-packagessetuptoolsbuild_meta.py", line 248, in run_setup
          super(_BuildMetaLegacyBackend,
        File "C:UsersadminAppDataLocalTemppip-build-env-0uexikepoverlayLibsite-packagessetuptoolsbuild_meta.py", line 142, in run_setup
          exec(compile(code, __file__, 'exec'), locals())
        File "setup.py", line 499, in <module>
          setup_package()
        File "setup.py", line 491, in setup_package
          setup(**metadata)
        File "C:UsersadminAppDataLocalTemppip-install-_drm9w48numpy_e4ace71c56d54bf7af156925b951ce98numpydistutilscore.py", line 169, in setup
          return old_setup(**new_attr)
        File "C:UsersadminAppDataLocalTemppip-build-env-0uexikepoverlayLibsite-packagessetuptools__init__.py", line 165, in setup
          return distutils.core.setup(**attrs)
        File "C:UsersadminAppDataLocalTemppip-build-env-0uexikepoverlayLibsite-packagessetuptools_distutilscore.py", line 148, in setup
          dist.run_commands()
        File "C:UsersadminAppDataLocalTemppip-build-env-0uexikepoverlayLibsite-packagessetuptools_distutilsdist.py", line 967, in run_commands
          self.run_command(cmd)
        File "C:UsersadminAppDataLocalTemppip-build-env-0uexikepoverlayLibsite-packagessetuptools_distutilsdist.py", line 986, in run_command
          cmd_obj.run()
        File "C:UsersadminAppDataLocalTemppip-build-env-0uexikepoverlayLibsite-packagessetuptoolscommanddist_info.py", line 31, in run
          egg_info.run()
        File "C:UsersadminAppDataLocalTemppip-install-_drm9w48numpy_e4ace71c56d54bf7af156925b951ce98numpydistutilscommandegg_info.py", line 24, in run
          self.run_command("build_src")
        File "C:UsersadminAppDataLocalTemppip-build-env-0uexikepoverlayLibsite-packagessetuptools_distutilscmd.py", line 313, in run_command
          self.distribution.run_command(command)
        File "C:UsersadminAppDataLocalTemppip-build-env-0uexikepoverlayLibsite-packagessetuptools_distutilsdist.py", line 986, in run_command
          cmd_obj.run()
        File "C:UsersadminAppDataLocalTemppip-install-_drm9w48numpy_e4ace71c56d54bf7af156925b951ce98numpydistutilscommandbuild_src.py", line 144, in run
          self.build_sources()
        File "C:UsersadminAppDataLocalTemppip-install-_drm9w48numpy_e4ace71c56d54bf7af156925b951ce98numpydistutilscommandbuild_src.py", line 155, in build_sources
          self.build_library_sources(*libname_info)
        File "C:UsersadminAppDataLocalTemppip-install-_drm9w48numpy_e4ace71c56d54bf7af156925b951ce98numpydistutilscommandbuild_src.py", line 288, in build_library_sources
          sources = self.generate_sources(sources, (lib_name, build_info))
        File "C:UsersadminAppDataLocalTemppip-install-_drm9w48numpy_e4ace71c56d54bf7af156925b951ce98numpydistutilscommandbuild_src.py", line 378, in generate_sources
          source = func(extension, build_dir)
        File "numpycoresetup.py", line 650, in get_mathlib_info
          st = config_cmd.try_link('int main(void) { return 0;}')
        File "C:UsersadminAppDataLocalTemppip-build-env-0uexikepoverlayLibsite-packagessetuptools_distutilscommandconfig.py", line 243, in try_link
          self._link(body, headers, include_dirs,
        File "C:UsersadminAppDataLocalTemppip-install-_drm9w48numpy_e4ace71c56d54bf7af156925b951ce98numpydistutilscommandconfig.py", line 161, in _link
          return self._wrap_method(old_config._link, lang,
        File "C:UsersadminAppDataLocalTemppip-install-_drm9w48numpy_e4ace71c56d54bf7af156925b951ce98numpydistutilscommandconfig.py", line 95, in _wrap_method
          ret = mth(*((self,)+args))
        File "C:UsersadminAppDataLocalTemppip-build-env-0uexikepoverlayLibsite-packagessetuptools_distutilscommandconfig.py", line 137, in _link
          (src, obj) = self._compile(body, headers, include_dirs, lang)
lscommandconfig.py", line 104, in _compile
          src, obj = self._wrap_method(old_config._compile, lang,
        File "C:UsersadminAppDataLocalTemppip-install-_drm9w48numpy_e4ace71c56d54bf7af156925b951ce98numpydistutilscommandconfig.py", line 95, in _wrap_method
          ret = mth(*((self,)+args))
        File "C:UsersadminAppDataLocalTemppip-build-env-0uexikepoverlayLibsite-packagessetuptools_distutilscommandconfig.py", line 132, in _compile
          self.compiler.compile([src], include_dirs=include_dirs)
        File "C:UsersadminAppDataLocalTemppip-build-env-0uexikepoverlayLibsite-packagessetuptools_distutils_msvccompiler.py", line 401, in compile
          self.spawn(args)
          return super().spawn(cmd, env=env)
        File "C:UsersadminAppDataLocalTemppip-install-_drm9w48numpy_e4ace71c56d54bf7af156925b951ce98numpydistutilsccompiler.py", line 90, in <lambda>
          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:pytodovenvlibsite-packages_distutils_hack__init__.py:33: UserWarning: Setuptools is replacing distutils.
  warnings.warn("Setuptools is replacing distutils.")
E:pytodovenvlibsite-packagesjieba_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:Usersfwrx.paddlenlptaskflowinformation_extractionuie-basemodel_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:Usersfwrx.paddlenlptaskflowinformation_extractionuie-baseconfig.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:Usersfwrx.paddlenlptaskflowinformation_extractionuie-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:Usersfwrx.paddlenlptaskflowinformation_extractionuie-basestaticinference
[2023-01-13 14:10:25,183] [    INFO] - We are using <class 'paddlenlp.transformers.ernie.tokenizer.ErnieTokenizer'> to load 'C:Usersfwrx.paddlenlptaskflowinformation_extractionuie-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文库

原文地址:https://blog.csdn.net/theorycao/article/details/128673664

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_20554.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注