【问题标题】:module 'numpy' has no attribute 'ndarray'模块“numpy”没有属性“ndarray”
【发布时间】:2021-12-01 11:40:41
【问题描述】:

非常感谢您的帮助!

我的 Jupiter notebook 被压坏了,所以我必须重新安装 notebook,但是在新的 Jupiter notebook 中,我无法运行 pandas。

import pandas as pd
AttributeError                            Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_6860/4080736814.py in <module>
----> 1 import pandas as pd

~\anaconda3\lib\site-packages\pandas\__init__.py in <module>
     20 
     21 # numpy compat
---> 22 from pandas.compat import (
     23     np_version_under1p18 as _np_version_under1p18,
     24     is_numpy_dev as _is_numpy_dev,

~\anaconda3\lib\site-packages\pandas\compat\__init__.py in <module>
     12 import warnings
     13 
---> 14 from pandas._typing import F
     15 from pandas.compat.numpy import (
     16     is_numpy_dev,

~\anaconda3\lib\site-packages\pandas\_typing.py in <module>
     82 # array-like
     83 
---> 84 ArrayLike = Union["ExtensionArray", np.ndarray]
     85 AnyArrayLike = Union[ArrayLike, "Index", "Series"]
     86 

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

我尝试重命名或删除 numpy.py,但没有成功。

【问题讨论】:

  • 卸载并重新安装 numpy? pip uninstall -y numpy 然后pip install numpy

标签: pandas numpy jupyter-notebook


【解决方案1】:

问题不在于 Pandas。这是由于 NumPy。我有一个类似的问题,这就是我所做的。

python -c "import numpy as np; print(np.__file__); print(np.ndarray)。预期输出将包含您安装的 NumPy 包的位置和第二个打印语句的&lt;class 'numpy.ndarray'&gt;。就我而言,NumPy 包似乎位于~/.local

我尝试在 conda 中重新安装 NumPy,但位置仍然相同。所以,按照this solution,我删除了~/.local。然后错误消失了。

【讨论】:

    【解决方案2】:

    只需尝试降级或升级 numpy 版本。它对我有用...

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2019-08-02
    • 1970-01-01
    • 1970-01-01
    • 2017-09-20
    • 2018-10-22
    • 2020-08-11
    • 1970-01-01
    • 1970-01-01
    • 2017-08-18
    相关资源
    最近更新 更多