Unresolved import errors yet successful import still occurs

[亡魂溺海] 提交于 2019-12-08 09:10:36

问题


I am working on a project in Eclipse Juno. I wrote a class called Character in a package named chargen.py. There's a red X next to from chargen import Character:

Unresolved import: Character
Character Found at: Avarice_v0.PlayAvarice_v0

from chargen import Character

Yet the import works. The entire code at the moment is simply this:

from chargen import Character

def main():
    PLAYER = Character("")
    print(PLAYER)

if __name__ == '__main__':
    main()

This code results in the printing of the __str__ proving the Character("") ran. Also, it generates no errors when running. Why does Eclipse label this Unresolved import: Character?


回答1:


I figured out how to get rid of the error. I moved everything one directory up. Settings for the project showed the PYTHONPATH included the main directory, but not the nested one. By moving it all up and deleting the now empty original folder, I have no unresolved import errors. This helped me to understand more about the PYTHONPATH choices offered at the initial setup of the project in PyDev.




回答2:


In the properties for your project, there's a pane called "PyDev - PYTHONPATH", with a sub-pane called "External Libraries". You can add source folders (any folder that has an init.py) to the path using that pane. Your project code will then be able to import modules from those source folders.



来源:https://stackoverflow.com/questions/14694112/unresolved-import-errors-yet-successful-import-still-occurs

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