酸酸酸359 2024-04-17 21:47 采纳率: 66.7%
浏览 58
已结题

AttributeError: module 'numpy' has no attribute 'bool'.

安装了seiscloud库以后执行命令出现以下报错:


/usr/lib/python3/dist-packages/scipy/io/matlab/mio5.py:98: FutureWarning: In the future `np.bool` will be defined as the corresponding NumPy scalar.
  from .mio5_utils import VarReader5
Traceback (most recent call last):
  File "/usr/local/bin/seiscloud", line 11, in <module>
    load_entry_point('seiscloud==0.1', 'console_scripts', 'seiscloud')()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 490, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2854, in load_entry_point
    return ep.load()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2445, in load
    return self.resolve()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2451, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/local/lib/python3.8/dist-packages/seiscloud/apps/seiscloud.py", line 15, in <module>
    from seiscloud import plot as scplot
  File "/usr/local/lib/python3.8/dist-packages/seiscloud/plot.py", line 9, in <module>
    from pyrocko import model, gmtpy
  File "/usr/local/lib/python3.8/dist-packages/pyrocko/gmtpy.py", line 12, in <module>
    from pyrocko.plot.gmtpy import *
  File "/usr/local/lib/python3.8/dist-packages/pyrocko/plot/gmtpy.py", line 30, in <module>
    from scipy.io import netcdf_file
  File "/usr/lib/python3/dist-packages/scipy/io/__init__.py", line 97, in <module>
    from .matlab import loadmat, savemat, whosmat, byteordercodes
  File "/usr/lib/python3/dist-packages/scipy/io/matlab/__init__.py", line 13, in <module>
    from .mio import loadmat, savemat, whosmat
  File "/usr/lib/python3/dist-packages/scipy/io/matlab/mio.py", line 12, in <module>
    from .mio5 import MatFile5Reader, MatFile5Writer
  File "/usr/lib/python3/dist-packages/scipy/io/matlab/mio5.py", line 98, in <module>
    from .mio5_utils import VarReader5
  File "mio5_utils.pyx", line 112, in init scipy.io.matlab.mio5_utils
  File "/home/u/.local/lib/python3.8/site-packages/numpy/__init__.py", line 305, in __getattr__
    raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'bool'.
`np.bool` was a deprecated alias for the builtin `bool`. To avoid this error in existing code, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

但是在报错里也没显示哪个文件里用了bool。
尝试降低numpy版本到1.19又发生报错:

Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [63 lines of output]
      Running from numpy source directory.
      <string>:460: UserWarning: Unrecognized setuptools command, proceeding with generating Cython sources and expanding templates
      /tmp/pip-install-7any6yby/numpy_dccdaf7812c84686bb2ce57cac55fedc/tools/cythonize.py:73: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
        required_version = LooseVersion('0.29.14')
      /tmp/pip-install-7any6yby/numpy_dccdaf7812c84686bb2ce57cac55fedc/tools/cythonize.py:75: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
        if LooseVersion(cython_version) < required_version:
      performance hint: _generator.pyx:706:41: Exception check after calling '_shuffle_int' will always require the GIL to be acquired.
      Possible solutions:
          1. Declare '_shuffle_int' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
          2. Use an 'int' return type on '_shuffle_int' to allow an error code to be returned.
      performance hint: _generator.pyx:735:45: Exception check after calling '_shuffle_int' will always require the GIL to be acquired.
      Possible solutions:
          1. Declare '_shuffle_int' as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
          2. Use an 'int' return type on '_shuffle_int' to allow an error code to be returned.
      
      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              for i in range(1, RK_STATE_LEN):
                  self.rng_state.key[i] = val[i]
              self.rng_state.pos = i
      
              self._bitgen.state = &self.rng_state
              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 the type of the value being assigned.
      Processing numpy/random/_bounded_integers.pxd.in
      Processing numpy/random/_generator.pyx
      Processing numpy/random/_mt19937.pyx
      Traceback (most recent call last):
        File "/tmp/pip-install-7any6yby/numpy_dccdaf7812c84686bb2ce57cac55fedc/tools/cythonize.py", line 235, in <module>
          main()
        File "/tmp/pip-install-7any6yby/numpy_dccdaf7812c84686bb2ce57cac55fedc/tools/cythonize.py", line 231, in main
          find_process_files(root_dir)
        File "/tmp/pip-install-7any6yby/numpy_dccdaf7812c84686bb2ce57cac55fedc/tools/cythonize.py", line 222, in find_process_files
          process(root_dir, fromfile, tofile, function, hash_db)
        File "/tmp/pip-install-7any6yby/numpy_dccdaf7812c84686bb2ce57cac55fedc/tools/cythonize.py", line 188, in process
          processor_function(fromfile, tofile)
        File "/tmp/pip-install-7any6yby/numpy_dccdaf7812c84686bb2ce57cac55fedc/tools/cythonize.py", line 77, in process_pyx
          subprocess.check_call(
        File "/home/u/anaconda3/lib/python3.10/subprocess.py", line 369, in check_call
          raise CalledProcessError(retcode, cmd)
      subprocess.CalledProcessError: Command '['/home/u/anaconda3/bin/python', '-m', 'cython', '-3', '--fast-fail', '-o', '_mt19937.c', '_mt19937.pyx']' returned non-zero exit status 1.
      Cythonizing sources
      Traceback (most recent call last):
        File "/home/u/anaconda3/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/home/u/anaconda3/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/home/u/anaconda3/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 149, in prepare_metadata_for_build_wheel
          return hook(metadata_directory, config_settings)
        File "/tmp/pip-build-env-c1alnbo9/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 366, in prepare_metadata_for_build_wheel
          self.run_setup()
        File "/tmp/pip-build-env-c1alnbo9/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 487, in run_setup
          super().run_setup(setup_script=setup_script)
        File "/tmp/pip-build-env-c1alnbo9/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 489, in <module>
        File "<string>", line 469, in setup_package
        File "<string>", line 274, in generate_cython
      RuntimeError: Running cythonize failed!
      [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.

  • 写回答

3条回答 默认 最新

  • 专家-赤兔[在线] 全栈领域优质创作者 2024-04-17 21:47
    关注

    引自免费微信小程序:皆我百晓生

    看起来你在尝试运行SeisCloud这个软件时遇到了一些与NumPy版本兼容性相关的问题。首先,让我们解决NumPy中的错误,然后处理降低NumPy版本后遇到的问题。

    针对第一个错误,这是由于NumPy在1.20版本开始弃用np.bool,建议使用标准Python内置类型bool。要解决这个问题,你需要找到引发此错误的具体代码行。通常,这样的错误是因为某个地方意外地使用了np.bool而不是bool。然而,由于报错信息没有提供具体的文件和行号,我们可以采取以下步骤来定位问题:

    1. 首先,检查seiscloud及其依赖项(特别是pyrockoscipy)的更新日志,看看是否有提到对NumPy新特性的使用。
    2. 如果更新日志没有明确说明,你可以逐个排查seiscloudpyrockoscipy的源码,查找所有使用np.bool的地方,并将其替换为bool

    对于第二个错误,当您试图降级到NumPy 1.19时,出现了Cython编译失败的问题。这可能是由于您的环境配置不正确,或者是某些依赖项之间的冲突。尝试以下方法来解决这个问题:

    1. 确保您的系统上已经安装了Cython:pip install cython
    2. 清除旧的构建缓存:rm -rf build dist *.egg-info
    3. 在干净的环境中尝试安装NumPy 1.19:pip install numpy==1.19.5 --no-cache-dir
    4. 如果上述步骤仍然失败,可能需要检查您的Conda环境设置是否正确,以及是否有其他软件包干扰了Cython的编译过程。

    如果你无法手动解决这些问题,可以考虑使用一个预先配置好的虚拟环境,例如Anaconda的环境管理器创建一个新的环境,确保所有的依赖都已正确安装并兼容。具体步骤如下:

    1. 创建一个新的Conda环境:`conda create -n seiscloud_env python=3.8 numpy=1.19.5 scipy seisc
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 4月25日
  • 已采纳回答 4月17日
  • 创建了问题 4月17日

悬赏问题

  • ¥15 matlab数据降噪处理,提高数据的可信度,确保峰值信号的不损失?
  • ¥15 怎么看我在bios每次修改的日志
  • ¥15 python+mysql图书管理系统
  • ¥15 Questasim Error: (vcom-13)
  • ¥15 船舶旋回实验matlab
  • ¥30 SQL 数组,游标,递归覆盖原值
  • ¥15 为什么我的数据接收的那么慢呀有没有完整的 hal 库并 代码呀有的话能不能发我一份并且我用 printf 函数显示处理之后的数据,用 debug 就不能运行了呢
  • ¥20 gitlab 中文路径,无法下载
  • ¥15 用动态规划算法均分纸牌
  • ¥30 udp socket,bind 0.0.0.0 ,如何自动选取用户访问的服务器IP来回复数据