views:

123

answers:

2

I'm an absolute beginner using IDLE (Python 2.6.4) to learn the basics. I recently found a Python program that I want to run but it throws an error although the code looks fine (i.e all modules exist):

from css.parse import parse

data = """
    em {
    padding: 2px; 
    margin: 1em;
    border-width: medium;
    border-style: dashed;
    line-height: 2.4em;
    }
    p { color: red; font-size: 12pt }
    p:first-letter { color: green; font-size: 200% }
    p:first-line { color: blue }"""

for rule in parse(data):
    print rule

for decl in parse(data)[0]:
    print decl

Error:

ImportError: No module named parse

How do I fix this? I'm using Snow Leopard.

Edit: I guess its a PATH issue, where should I place the modules, which directory?

+1  A: 

You should have your test.py script in the same folder as the folder, not in the folder.

So it should look like this:

../
 test.py
 css/
DoR
Yes it does. I guess its a PATH issue which I don't quite understand.
Nimbuz
Can you post the link to this program?
DoR
http://code.google.com/p/css-py/
Nimbuz
So how exactly are you running this? I appears to be a module that you would import from a separate script.
DoR
I extracted/copied the 'css' folder on my disk, and created a new test.py file in the same folder to run an example (code.google.com/p/css-py/wiki/Examples) and I get this error. –
Nimbuz
Ah, ok. I moved the test.py outside the folder, the original errors seems to have gone but now, uh, another similar error popped up: ImportError: No module named ply
Nimbuz
You'll need to install this library: http://pypi.python.org/pypi/ply/3.1
DoR
Great, think I got it working, but the output is not what I'd expected though: --------------------------------------------------WARNING: Token 'INVALID' defined, but not usedWARNING: Token 'DIMENSION' defined, but not usedWARNING: There are 2 unused tokensGenerating LALR tablesWARNING: 149 shift/reduce conflictsPLY: PARSE DEBUG STARTState : 0Stack : . LexToken(S,'\n ',1,0)Action : Shift and goto state 4....
Nimbuz
Could be a bug, ask for help here http://code.google.com/p/css-py/issues/list
DoR
Or maybe I'm not using the compatible ply version. Thanks anyway though, I'd better stop hear and learn more Python before asking for more help! Thanks again! :)
Nimbuz
+1  A: 

A generic but useful reference regarding the way Python module search path is
this brief but informative section of Python Documentation

The default paths and the environmental variables which allow configuring this important feature of the interpreter varies with different Operating Systems, so it is important to know this info for troubleshooting situations similar to that of Nimbuz.

Also the IDEs themselves can add yet another layer of configuration/indirection...

mjv