python newb has problem with import statements

Discussion in 'Python' started by danielmcbrearty@gmail.com, Mar 19, 2006.

  1. Guest

    Hi

    Old hand at perl, giving python a try. Trying to get pymedia running on
    my winxp box.

    Have installed activestate python 2.4 and pymedia using precompiled
    installers.

    Problem is it SEEMS that the __init__.py is not getting run when I
    import a module.

    So, I have pymedia installed and it imports fine:

    >>> import pymedia
    >>> dir(pymedia)

    ['__builtins__', '__doc__', '__file__', '__name__']
    >>>


    the init file looks like this:

    (docs and comments skipped)

    print "in pymedia" # added by me to see
    __all__= [ 'muxer', 'audio', 'video', 'removable' ]
    import muxer, audio, video, removable

    but I can't import submodules of pymedia:

    >>> import pymedia.sound

    Traceback (most recent call last):
    File "<interactive input>", line 1, in ?
    ImportError: No module named sound
    >>>


    if I do this

    >>> from pymedia import *
    >>> import pymedia.sound

    Traceback (most recent call last):
    File "<interactive input>", line 1, in ?
    ImportError: No module named sound
    >>>


    the weird thing is teh IDE (pythonwin) knows about the sub modules - it
    shows them in the auto-suggest thingy when I type "pymedia."

    so what's going on? do I have an install problem? (I did try removing
    and reinstalling, no avail) am I just misunderstanding how this should
    work?

    all helpful stuff much appreciated

    Daniel
     
    , Mar 19, 2006
    #1
    1. Advertising

  2. Peter Otten Guest

    wrote:

    > the init file looks like this:
    >
    > (docs and comments skipped)
    >
    > print "in pymedia" # added by me to see
    > __all__= [ 'muxer', 'audio', 'video', 'removable' ]
    > import muxer, audio, video, removable
    >
    > but I can't import submodules of pymedia:


    The file with the contents given above is clearly not the one that is
    imported here,

    > >>> import pymedia
    > >>> dir(pymedia)

    > ['__builtins__', '__doc__', '__file__', '__name__']


    as __all__, muxer, audio etc. are missing.

    Maybe you have created a test script 'pymedia.py' in the working directory?
    You can check what file you are dealing with by entering

    >>> pymedia.__file__


    If that is 'whatever/site-packages/pymedia/__init__.pyc' I'm guessing wrong.
    Otherwise removing that file (probably 'pymedia.pyc') and the corresponding
    source (pymedia.py) should fix your problem.

    Peter
     
    Peter Otten, Mar 19, 2006
    #2
    1. Advertising

  3. Guest

    that was indeed the problem. Thanks!
     
    , Mar 19, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neil Zanella
    Replies:
    8
    Views:
    1,195
    mfmehdi
    Oct 20, 2006
  2. Jon Moldover
    Replies:
    0
    Views:
    302
    Jon Moldover
    Oct 28, 2003
  3. Harry George
    Replies:
    6
    Views:
    379
    Bart Nessux
    Feb 23, 2004
  4. Vince
    Replies:
    12
    Views:
    751
    Martin Gregorie
    Jan 21, 2008
  5. STEPHEN BECKER I V

    {newb} Each statements

    STEPHEN BECKER I V, Sep 27, 2004, in forum: Ruby
    Replies:
    14
    Views:
    174
    Brian Candler
    Sep 28, 2004
Loading...

Share This Page