Unresolved Import

Lin Parkh
2008-09-18
2013-03-15
  • Lin Parkh

    Lin Parkh - 2008-09-18

    Hi,
    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 :-)
      Thanks!
       Lin
     

     
    • Fabio Zadrozny

      Fabio Zadrozny - 2008-09-18

      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:
      /home/lin/pygame
      /home/lin/pygame/__init__.py

      and the folder added to the pythonpath should be be /home/lin

      Cheers,

      Fabio

       
      • Lin Parkh

        Lin Parkh - 2008-09-19

        Thanks for replying.  I have both the parent directory and the pygame directory in the python path:
        C:\Python25\Lib\site-packages
        C:\Python25\Lib\site-packages\pygame

        I checked and there is __init__.py and __init__.pyc in the pygame directory.... (and I did do an "apply" as I added these)
          Thoughts?

         
        • Tim Diggins

          Tim Diggins - 2008-09-19

          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.)

          hth

          -- Tim

           
          • Lin Parkh

            Lin Parkh - 2008-09-19

            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.
              Lin

             
            • Fabio Zadrozny

              Fabio Zadrozny - 2008-09-24

              Hi Lin,

              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).

              Cheers,

              Fabio