470,643 Members | 1,551 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,643 developers. It's quick & easy.

python newb has problem with import statements

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 '06 #1
2 1728
da*************@gmail.com 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
Mar 19 '06 #2
that was indeed the problem. Thanks!

Mar 19 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

54 posts views Thread by Brandon J. Van Every | last post: by
8 posts views Thread by Gekitsuu | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.