AttributeError 测试文章
----
AttributeError Traceback (most recent call last)
Cell In[37], line 3
1 import matplotlib.pyplot as plt
2 import numpy as np
----> 3 import pandas as pd
4 import parselmouth
File D:\Python\CondaEnvs\Praat\Lib\site-packages\pandas\__init__.py:37
30 _module = _err.name
31 raise ImportError(
32 f"C extension: {_module} not built. If you want to import "
33 "pandas from the source directory, you may need to run "
34 "'python setup.py build_ext' to build the C extensions first."
35 ) from _err
---> 37 from pandas._config import (
38 get_option,
39 set_option,
40 reset_option,
41 describe_option,
42 option_context,
43 options,
44 )
46 # let init-time option registration happen
47 import pandas.core.config_init # pyright: ignore[reportUnusedImport] # noqa: F401
File D:\Python\CondaEnvs\Praat\Lib\site-packages\pandas\_config\__init__.py:20
1 """
2 pandas._config is considered explicitly upstream of everything else in pandas,
3 should have no intra-pandas dependencies.
(...)
6 are initialized.
7 """
8 __all__ = [
9 "config",
10 "detect_console_encoding",
(...)
18 "warn_copy_on_write",
19 ]
---> 20 from pandas._config import config
21 from pandas._config import dates # pyright: ignore[reportUnusedImport] # noqa: F401
22 from pandas._config.config import (
23 _global_config,
24 describe_option,
(...)
29 set_option,
30 )
File D:\Python\CondaEnvs\Praat\Lib\site-packages\pandas\_config\config.py:68
58 from typing import (
59 TYPE_CHECKING,
60 Any,
(...)
64 cast,
65 )
66 import warnings
---> 68 from pandas._typing import (
69 F,
70 T,
71 )
72 from pandas.util._exceptions import find_stack_level
74 if TYPE_CHECKING:
File D:\Python\CondaEnvs\Praat\Lib\site-packages\pandas\_typing.py:198
192 Frequency = Union[str, "BaseOffset"]
193 Axes = ListLike
195 RandomState = Union[
196 int,
197 np.ndarray,
--> 198 np.random.Generator,
199 np.random.BitGenerator,
200 np.random.RandomState,
201 ]
203 # dtypes
204 NpDtype = Union[str, np.dtype, type_t[Union[str, complex, bool, object]]]
AttributeError: module 'numpy.random' has no attribute 'Generator'
原因
conda 与 numpy版本不一致
解决方法
pip uninstall conda numpy
pip install conda numpy