【bug】【Cannot find reference 'imread' in '__init__.py | __init__.py'】

pycharm开启了代码智能提示,opencv模块正确导入了,代码可以正常运行,但是,会有

Cannot find reference 'imread' in '__init__.py | __init__.py'

的warning,而且没有代码提示,不能获取documentation,也不能查看源码,不能提示形参列表,排查了很久,不知道为何。

找到一个相关的问题:

python - Cannot find reference 'xxx' in init.py - Stack Overflow

不是很理解

PyCharm looks at the __init__.py file to traceback to the module where a function/variable resides. So without __all__ having the modules names, it can't traceback to the source.

我的推测也是pycharm这样做并不是bug,而是根据__init__.py文件中的__all__全局变量来进行索引。

关闭这个warning是简单的,但没有必要,而且即使关闭warning,代码提示功能依旧不起作用。

后面我通过修改opencv的版本,完美的解决了这个问题,没有warning,并且代码提示功能也正常了。

有问题的版本是

可以看到其__init__.py文件中的__all__变量声明

居然是空的,不清楚到底原因是不是因为这个__all__

之后我修改了opencv的版本,改为4.5.3.56,问题解决了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章