wodemoneke
wodemoneke

Reputation: 343

import statement fails for one module

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.

Upvotes: 2

Views: 677

Answers (4)

Jason Baker
Jason Baker

Reputation: 198547

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.

Upvotes: 1

S.Lott
S.Lott

Reputation: 391818

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.

Upvotes: 2

SilentGhost
SilentGhost

Reputation: 319551

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.

Upvotes: 2

Clint
Clint

Reputation: 4253

Does the following work?

import snipplets.options.Options

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

Upvotes: 1

Related Questions