1

I have a project with the following layout:

project_root
    __init__.py
    typing
        __init__.py
        bset.py (contains a class BSet)
    environment
        __init__.py
        environment.py

from within environment.py I'm trying to import bset.BSet

from ..typing import bset

def do_something():
    b = bset.BSet()

When I try to run environment.py (either directly, or under my test runner) I get:

Traceback (most recent call last):
  File "environment/environment.py", line 3, in <module>
    from ..typing import bset
ValueError: Attempted relative import in non-package

I'd like the whole thing to function as a module ("project_root"), and I thought I had it working but I appear to have made a change that broke it.

What is the correct way to set up the inter-submodule dependencies?

John Carter
  • 6,752
  • 2
  • 32
  • 53
  • The tricky part of relative imports is that if you run `environment.py` (e.g. `~$ python environment.py`) then it doesn't act like part of its module. You need to run it somewhere at the project root so that its structure is preserved – Adam Smith Apr 04 '15 at 19:33

0 Answers0