Rasmus
Rasmus

Reputation: 8486

Yet another python import issue of mine

Looks like I am having a real tough day with python imports.I am using Flask and am trying to organise my app structure.I am using it on GAE and thus have to put python packages in my app itself. It looks something like this below:-

-MyFolder
  -flask
  -werkzeug
  -Myapp
    - __init__.py
    -templates
    -static
    -views.py
  -blinker

As of now I import the blinker library into Myapp's __init__. But I wanted to organise these extra packages like blinker into a helper package so as to look like this.

-helper
 -__init__.py
 -blinker

(blinker's __init__.py file looks like this)

from blinker.base import.....

But when I try importing blinker into Myapp's __init__ using

from helper import blinker

I get an import error saying no module named blinker.base.Why should that happen. Looks like it looks for a blinker package outside of the current one. Why should it happen?

Upvotes: 2

Views: 2876

Answers (2)

Pwnna
Pwnna

Reputation: 9538

sys.path.append could also fit your purpose.

Upvotes: 1

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798746

Smells like you want to be using a relative import.

from .base import ...

Upvotes: 0

Related Questions