AttributeError: module ‘numpy‘ has no attribute ‘int‘.错误解决

在使用sklearn和pandas和numpy时出现这个问题,具体报错为:

Traceback (most recent call last): 
File "D:\新建文件夹\text_cluster-main\text_cluster-main\train.py", line 10, in  from 
kmeans import KMEANS File "D:\新建文件夹\text_cluster-main\text_cluster-main\kmeans.py", 
line 9, in  from sklearn.feature_extraction.text import TfidfVectorizer, 
HashingVectorizer, TfidfTransformer File "D:\anaconda3\envs\textbert\lib\site-
packages\sklearn\feature_extraction\__init__.py", line 9, in  from .image import 
img_to_graph, grid_to_graph File "D:\anaconda3\envs\textbert\lib\site-
packages\sklearn\feature_extraction\image.py", line 172, in  dtype=np.int): File 
"D:\anaconda3\envs\textbert\lib\site-packages\numpy\__init__.py", line 305, in __getattr__ 
raise AttributeError(__former_attrs__[attr]) AttributeError: module 'numpy' has no 
attribute 'int'. `np.int` was a deprecated alias for the builtin `int`. To avoid this error 
in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. 
When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the 
precision. If you wish to review your current use, check the release note link for 
additional information. 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 进程已结束,退出代码1的结果。

 这时因为numpy版本大于1.20不支持int,现在我使用的版本为1.24

解决方法为修改numpy的版本为1.23,然后报错就没了

pip install numpy==1.23

参考链接为:module ‘numpy‘ has no attribute ‘int‘_module 'numpy' has no attribute 'int_AI视觉网奇的博客-CSDN博客

你可能感兴趣的:(科研问题记录,numpy)