1

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?

Red X In Eclipse Example

Vin Breau
  • 269
  • 3
  • 17

2 Answers2

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.

Vin Breau
  • 269
  • 3
  • 17
0

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.

Walls
  • 3,972
  • 6
  • 37
  • 52
  • Your answer raises a question I've had for a while now. Since chargen.py is within the same folder as PlayAvarice, the import looks also within the same directory right? That's why this import works. Seems like the error means that the package chargen.py is not in the PYTHONPATH. When I am creating a new project in Eclipse, it asks if I want to add the directory to the PYTHONPATH, create an SRC and add it, or add it manually later... is this error a result of have chosen an inappropriate selection at project creation? I'm never sure which choice is right for each project. – Vin Breau Feb 04 '13 at 20:11
  • It's like setting up external references. If you aren't going to be creating a lot of things that aren't all interconnected, I think you are ok leaving it out. But when you are working on things you plan on using across different projects, it may help to add it at the beginning so this doesn't pop up again in the future. – Walls Feb 04 '13 at 20:15