经过

1
2
3
4
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

在将k折交叉验证的代码加入自己的模型(yolo-based)的过程中,出现了np.int 不适用的情况,于是降低版本,但是随着numpy降低版本导致了原本的pandas也不能使用,于是继续降低pandas的版本,此时,又导致了matplotlib报错。

解决

在一个教程中同时出现了deprecated和remove的两个单词,所以上网查询,尝试,numpy这个方法在1.20.1中是deprecated状态,而在1.20.4中才被remove。因而只要选在之间的版本即可完成。

deprecated库

在python中,如果你有函数或者类当下没有作用,或者即将废弃,但是你又不想删除,那么你可以标记为deprecated。java代码中的类或者函数只要标记了@Deprecated在其他地方均可以直观的显示删除线,python可以通过这个库来完成。

1
pip install Deprecated
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import warnings

from deprecated.sphinx import deprecated

warnings.filterwarnings("always")


@deprecated(version='1.0', reason="This function will be removed soon")
def some_old_function(x, y):
warnings.warn("some_old_function is deprecated", DeprecationWarning)
return x + y


if __name__ == '__main__':
some_old_function(12, 34)
help(some_old_function)

![image-20231008192211085](/Users/feng/Library/Application Support/typora-user-images/image-20231008192211085.png)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Help on function some_old_function in module __main__:

some_old_function(x, y)
.. deprecated:: 1.0
This function will be removed soon
~
~
~
~
~
~
~
~
~
~
~
~
~