PyCharm reporting no module found but when I go to look for it then it's there in the correct directory

假装没事ソ 提交于 2020-12-16 04:34:45

问题


My application is running in PyCharm and giving me an error saying:

File "/Users/Alan/PycharmProjects/anki4/qt/aqt/__init__.py", line 17, in <module>
import aqt.buildinfo

ModuleNotFoundError: No module named 'aqt.buildinfo'

When I hover over that line it shows this:

But I can go to the terminal and confirm it's there:

% cd /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/aqt/
% ls build*

buildinfo.py    
% cat buildinfo.py
buildhash='70784154'
version='2.1.26' 

Does anyone have any idea what's wrong?


回答1:


its looking at this /Users/Alan/PycharmProjects/anki4/qt/aqt/ folder ...

but that doesnt exist in that folder ...

apparently it is found here /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/aqt/ ... but that doesnt matter because /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/aqt/ is being shadowed by /Users/Alan/PycharmProjects/anki4/qt/aqt/

consider the following

print(sum([1,2,3,4,5])) # 15
sum = 15
print(sum([1,2,3,4,5])) # Error... because you have shadowed the builtin sum

the same problem exists for modules

if i have a file named os.py ... and i open a python terminal in that folder and say import os i will import my os.py not the system os module that i probably am actually trying to import



来源:https://stackoverflow.com/questions/61906604/pycharm-reporting-no-module-found-but-when-i-go-to-look-for-it-then-its-there-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!