karajan1001
karajan1001

Reputation: 250

Not a package error even if I had a __init__.py in it

I am doing a project on a Macbook, its system is OS X 10.11.5. I used Python 3.5 and had a directory like this

rec-par/
    rec/
        __init__.py
        cle/
            __init__.py
            c.py
        par/
            __init__.py
            b.py
        util/
            __init__.py
            a.py

in a.py there is a import like

from rec.par.b import *

And it got a error like 'No module name rec.par , rec is not a package'. I have added the path 'rec-par' to the sys.path and in cle/c.py there is no error with the same import command.

I tried the methods given in Question How to fix "Attempted relative import in non-package" even with __init__.py, used python3 -m a.py . But it didn't work.

Is there anything I missing here?

Upvotes: 3

Views: 7667

Answers (2)

karajan1001
karajan1001

Reputation: 250

OK, I had solved this problem. In the directory util/__pycache__ There was a file par.cpython-35.py which had the same name with the directory package. This caused a confusion. After it been deleted , The problem solved.

Upvotes: 5

Domme
Domme

Reputation: 141

The module in your code is called "rec-par", but when trying to import it you refer to "rec.par".

Upvotes: 0

Related Questions