问题描述:运行一个网上下载的PyQt5代码,出现了AttributeError: module 'numpy' has no attribute 'typeDict'的错误。具体如下:
Traceback (most recent call last):
File "F:/PyQt5/Javacr/main.py", line 16, in <module>
from models.experimental import attempt_load
File "F:\PyQt5\Javacr\models\experimental.py", line 11, in <module>
from models.common import Conv
File "F:\PyQt5\Javacr\models\common.py", line 27, in <module>
from utils.plots import Annotator, colors, save_one_box
File "F:\PyQt5\Javacr\utils\plots.py", line 16, in <module>
import seaborn as sn
File "C:\Users\aoqia\anaconda3\envs\yolov5_pyqt5\lib\site-packages\seaborn\__init__.py", line 2, in <module>
from .rcmod import * # noqa: F401,F403
File "C:\Users\aoqia\anaconda3\envs\yolov5_pyqt5\lib\site-packages\seaborn\rcmod.py", line 7, in <module>
from . import palettes
File "C:\Users\aoqia\anaconda3\envs\yolov5_pyqt5\lib\site-packages\seaborn\palettes.py", line 9, in <module>
from .utils import desaturate, get_color_cycle
File "C:\Users\aoqia\anaconda3\envs\yolov5_pyqt5\lib\site-packages\seaborn\utils.py", line 10, in <module>
from scipy import stats
File "C:\Users\aoqia\anaconda3\envs\yolov5_pyqt5\lib\site-packages\scipy\stats\__init__.py", line 384, in <module>
from .stats import *
File "C:\Users\aoqia\anaconda3\envs\yolov5_pyqt5\lib\site-packages\scipy\stats\stats.py", line 179, in <module>
from scipy.spatial.distance import cdist
File "C:\Users\aoqia\anaconda3\envs\yolov5_pyqt5\lib\site-packages\scipy\spatial\__init__.py", line 97, in <module>
from .kdtree import *
File "C:\Users\aoqia\anaconda3\envs\yolov5_pyqt5\lib\site-packages\scipy\spatial\kdtree.py", line 8, in <module>
import scipy.sparse
File "C:\Users\aoqia\anaconda3\envs\yolov5_pyqt5\lib\site-packages\scipy\sparse\__init__.py", line 229, in <module>
from .base import *
File "C:\Users\aoqia\anaconda3\envs\yolov5_pyqt5\lib\site-packages\scipy\sparse\base.py", line 8, in <module>
from .sputils import (isdense, isscalarlike, isintlike,
File "C:\Users\aoqia\anaconda3\envs\yolov5_pyqt5\lib\site-packages\scipy\sparse\sputils.py", line 17, in <module>
supported_dtypes = [np.typeDict[x] for x in supported_dtypes]
File "C:\Users\aoqia\anaconda3\envs\yolov5_pyqt5\lib\site-packages\scipy\sparse\sputils.py", line 17, in <listcomp>
supported_dtypes = [np.typeDict[x] for x in supported_dtypes]
File "C:\Users\aoqia\anaconda3\envs\yolov5_pyqt5\lib\site-packages\numpy\__init__.py", line 320, in __getattr__
raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'typeDict'
原因分析:numpy的版本太高了。项目中要求安装numpy>=1.18.5,我安装了numpy==1.24.3版本的,具体如下图所示:
图1 项目要求的numpy版本
图2 默认安装的 numpy版本
解决办法:将numpy版本降下来。比如安装1.2.1版本的numpy。
pip install numpy==1.21