views:

29

answers:

0

My project has the following structure:

setup.py
project/
    __init__.py
    main.py
    errors.py
    lib/
        li1b.py
        lib2.py

I'm importing the errors module with from . errors import Error1, Error2, Error3 which works fine when running the program with python main.py. However when I build and install it as an egg with python setup.py develop I get the error no module errors exists when running it.

This can be fixed this by changing the import to from project.errors import Error1, Error2, Error3 but then running it with python main.py gets the same error.

As I'd prefer to not have to change my imports to do a release - is there some way to have an import that works for both types?

EDIT: I can make it work with:

try:
    from project.errors import *
except ImportError:
    from .errors import *

But this doesn't feel very clean or pythonic!