I've the latest pydev extensions with Python 2.5. I've installed pygame library and can access it's modules. However I'm getting an error (from Pydev) "unresolved import: pygame". There is no pygame module per se only a folder of many other modules. I'm learning python and pygame together. The sample tutorial code I have is clear that I should say "import pygame"... and then I can the non runtime error. I'm thinking that maybe I didn't declare this folder as a "package" somehow. Maybe I need to formally bring it in to pydev insomehow? It is in the PYDEV path for the interperter btw.
Please advise. THis is non lethal but but getting a red X sitting next to my code is distracting and I want my code to be clean :-)
So, just to check... have you added the folder above the 'pygame' folder to the pythonpath? Does pygame have an __init__.py file within it?
E.g.: So, you should have:
and the folder added to the pythonpath should be be /home/lin
Thanks for replying. I have both the parent directory and the pygame directory in the python path:
I checked and there is __init__.py and __init__.pyc in the pygame directory.... (and I did do an "apply" as I added these)
I think you should remove the pygame directory, for starters... Although this may not solve your problem, it can't be helping (python searches all directories in the python path for package names and module names... if site-packages is in the python path (which it should be) then python will search it for "pygame"... You don't want python searching within pygame for things that are not within the pygame package.)
So if I understand you you are saying once I name a directory for search I don't need to name it's subdirectories. So remove pygame becasue it is a subdirectory of site pcckages. Makes sense. However can you explain to me please why then after installation of python/pydev my PYTHONPATH includes a bunch of subdirectories of Python25 like \Dll \lib etc? I didn't put these in so presumably they were automatically put there for some good reason. I'm not doubting you just trying to understand what the rule is for when subdirectories are listed...maybe directories that are directly below python25? Thanks for your response and your time.
Those are the default paths with libraries from Python. Each place that has modules that can be imported must be added... and it must have __init__.py in all the subdirectories all the way until the file you want (otherwise python won't recognize it as a valid python package -- I think that's the only reason to have subdirectories in the pythonpath even when its parent is also in the pythonpath).