module 'numpy' has no attribute 'complex'
时间: 2023-10-02 19:11:33 浏览: 506
python报错: list object has no attribute shape的解决
出现"module 'numpy' has no attribute 'complex'"错误是因为在numpy中使用了已经被弃用的np.complex属性。为了避免这个错误,在现有代码中应该改用complex属性。这样做不会改变任何行为,并且是安全的。
如果你想重新安装numpy,你可以使用以下命令:
pip uninstall numpy
pip install numpy==1.22
另外,如果你在训练YOLO模型时遇到这个错误,很可能是由于numpy版本不兼容造成的。官方要求的numpy版本是大于等于1.18.5。然而,当你执行pip install -r requirements.txt命令时,默认安装的是numpy 1.24版本。在numpy 1.20中已弃用numpy.int,在numpy 1.24中已删除。以下是两种解决方案:
1. 将numpy版本降级到1.18.5或更高版本:
pip install numpy==1.18.5
2. 如果你已经安装了numpy 1.24,你可以使用下面的代码来解决问题:
import numpy as np
np.compat.long = np.int
通过这些解决方案,你应该能够解决"module 'numpy' has no attribute 'complex'"的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [numpy‘ has no attribute ‘complex‘.](https://blog.csdn.net/qq_15821487/article/details/130842655)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [AttributeError: module numpy has no attribute int .报错解决方案](https://blog.csdn.net/weixin_46669612/article/details/129624331)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文