尚未解决的导入错误仍然会成功导入 [英] Unresolved import errors yet successful import still occurs
问题描述
我正在Eclipse Juno中开展一个项目。我在一个名为chargen.py的包中写了一个名为Character的类。来自chargen import字符的旁边有一个红色的X
:
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()
此代码导致打印 __ str __
证明字符(跑了。此外,它在运行时不会产生任何错误。为什么Eclipse标记此未解析的导入:字符
?
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
?
推荐答案
我想出了如何获得摆脱错误。我把一个目录都移到了一起。项目的设置显示PYTHONPATH包含主目录,但不包括嵌套目录。通过将其全部移动并删除现在空的原始文件夹,我没有未解决的导入错误。这有助于我更好地了解PyDev项目初始设置中提供的PYTHONPATH选项。
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.
这篇关于尚未解决的导入错误仍然会成功导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!