4

There are many questions about "unresolved import" for Python with PyDev in Eclipse. NB Linux Mint 18.3 OS, Python3, Eclipse "2019-06", PyDev 7.3.0...

I just hoped someone might be able to confirm my understanding on this:

Directory structure:

project directory: PyDevExp
  directory: mygame
    file: draw.py
    file: game.py

game.py looks like this:

# game.py
# import the draw module
import draw

def play_game():
    ...

def main():
    result = play_game()
    draw.draw_game()

if __name__ == '__main__':
    main()

When I run this at the command line:

python3 game.py

... it runs fine, no complaints. But when I view it in Eclipse there's a horrid red mark next to the import line. I can only get rid of it by adding directory "mygame" to the project's PYTHONPATH.

Surely this is ridiculous? Why can't PyDev "see" other files in the same directory without this having to be explicitly configured? Or am I doing something wrong?

later
The thing even runs OK in Eclipse! So for now I've changed the notification level from "error" to "info" for Windows --> Prefs --> PyDev --> Editor --> Code Analysis --> Imports tab --> "Import not found".

Unsatisfactory!

2
  • Any luck finding a real solution to this other than hiding the error? I'm having the same issue... Commented Jun 30, 2020 at 3:51
  • No, as of today I get the same thing. What I find strange is that no-one else seems to be complaining about this. I'm not sure what causes it to happen, or whether it happens with every project I create. Commented Jan 2, 2022 at 19:17

2 Answers 2

1

Right-click on your project (PyDevExp) and select PyDev. You will probably see an option to remove the folder from PYTHONPATH. It looks to me as though project folders are now added to PYTHONPATH by default. In which case you can get rid of the error marker by changing "import draw" to "import mygame.draw". But you might prefer just to put up with the spurious error.

Sign up to request clarification or add additional context in comments.

Comments

0

To avoid the error on Eclipse, just do right click on mygame directory, and go to PyDev -> Set as source folder (add to PYTHONPATH), as you can see in the image. Then, you can import your files in the right way in order to test it in Eclipse.

PyDEV set as source folder Pythonpath

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.