numpy 导入海运模块时出错:属性错误

uelo1irk  于 2023-08-05  发布在  其他
关注(0)|答案(1)|浏览(125)

我安装了seaborn作为

!pip install seaborn --upgrade --quiet

字符串
但当我试图导入它使用

import seaborn as sns


我得到以下错误。

---------------------------------------------------------------------------
AttributeError                            
Traceback (most recent call last)
<ipython-input-92-a84c0541e888> in <module>
----> 1 import seaborn as sns

14 frames
/usr/local/lib/python3.8/dist-packages/numpy/__init__.py in __getattr__(attr)
    311             x = ones(2, dtype=float32)
    312             if not abs(x.dot(x) - float32(2.0)) < 1e-5:
--> 313                 raise AssertionError()
    314         except AssertionError:
    315             msg = ("The current Numpy installation ({!r}) fails to "

AttributeError: module 'numpy' has no attribute '_no_nep50_warning'


我尝试卸载和重新安装,但它不工作。此外,关闭并启动了笔记本,但问题仍然相同。

v8wbuo2f

v8wbuo2f1#

Numpy似乎缺少一个decorator _no_nep50_warning来发出可选的警告。这个装饰器的用途在https://numpy.org/neps/nep-0050-scalar-promotion.html中有文档说明。遇到的问题是版本不兼容,包维护人员应该解决,对于我的环境,它还涉及其他包,如sklearn。
对于这个特定的问题,可以尝试手动降级numpy

!pip install numpy==1.23.3 --quiet --ignore-installed

字符串
但我不建议你这么做应该使用包管理器来解决兼容性问题。
假设你可以在没有numpy这个可选特性的情况下生活,并理解你会错过哪些警告。然后,下面的代码片段将装饰器的一个虚拟替换放入numpy中,从而允许导入seaborn:

import numpy as np
def dummy_npwarn_decorator_factory():
  def npwarn_decorator(x):
    return x
  return npwarn_decorator
np._no_nep50_warning = getattr(np, '_no_nep50_warning', dummy_npwarn_decorator_factory)

import seaborn as sns  # now should work


如果装饰器存在于numpy中,这段代码不会改变它。

相关问题