tags:

views:

133

answers:

4

Ok I found the problem, it was an environmental issue, I had the same modules (minus options.py) on the sys.path and it was importing from there instead. Thanks everyone for your help.

I have a series of import statements, the last of which will not work. Any idea why? options.py is sitting in the same directory as everything else.

from snipplets.main import MainHandler
from snipplets.createnew import CreateNewHandler
from snipplets.db import DbSnipplet
from snipplets.highlight import HighLighter
from snipplets.options import Options

ImportError: No module named options

my __init__.py file in the snipplets directory is blank.

+2  A: 

I suspect that one of your other imports redefined snipplets with an assignment statement. Or one of your other modules changed sys.path.


Edit

"so the flow goes like this: add snipplets packages to path import..."

No.

Do not modify sys.path -- that way lies problems. Modifying site.path leads to ambiguity about what is -- or is not -- on the path, and what order they are in.

The simplest, most reliable, most obvious, most controllable things to do are the following. Pick exactly one.

  • Define PYTHONPATH (once, external to your program). A single, simple environment variable that is nearly identical to installation on site-packages.

  • Install your package in site-packages.

S.Lott
so the flow goes like this:add snipplets packages to pathimport snipplets modulesI tried moving the options import above everything else, but no change.
wodemoneke
It would be my plan to add it to site-packages when distributed, but It's still under development. Why would it be bad to modify sys.path?
wodemoneke
+2  A: 

your master branch doesn't have options.py. could it be that you dev and master branches are conflicting?

if this is your actual code then you have option variable at line 21.

SilentGhost
No i'm just using the dev branch currently, master hasn't been updated.
wodemoneke
nice catch, its poor naming, but that's not the problem.
wodemoneke
i've tried your code and had no problems with import. I'm still convinced that it's a clash of two branches.
SilentGhost
Are you running from the dev branch? I tried a fresh version on my machine, still has the same problem. Perhaps its something on my machine only.
wodemoneke
+1  A: 

Does the following work?

import snipplets.options.Options

If so, one of your other snipplets files probably sets a global variable named options.

Clint
unfortunately, it doesn't work :(
wodemoneke
+1  A: 

Are you on windows? You might want to try defining an __all__ list in your __init__.py file like noted here. It shouldn't make a difference unless you're importing *, but I've seen modules not import unless they were defined there.

Secondly, you might try setting up a virtualenv. Using a lot of site-wide python packages can lead to these kinds of things.

Lastly, make sure the permissions of options are set correctly. I've spent hours trying to figure these things out only to find out it was an issue of me not having permission to import it.

Jason Baker
I'm on linux, so your first point doesn't apply.I'll take a look at the virtualenv
wodemoneke
permissions seem fine too.
wodemoneke