0

EDIT: Found a solution

I'm writing a new package (in jupyter lab) with following structure (folder names start with capital letter):

Package
    setup.py
    Rsp
    __init__.py
        Auxi
            __init__.py
            madn.py
            wtuk.py
        LocSc
            __init__.py
            tuk.py
            Examples
                __init__.py
                script.py

All init.py files are empty.

My current working directory is Examples.

I want to run script.py

In script.py I import tuk.py by

import sys
sys.path.append('..')
import tuk

tuk.py imports madn and wtuk. This is where I am having problems.

from ..Auxi.madn import madn
from ..Auxi.wtuk import wtuk

yields: attempted relative import with no known parent package

import sys
sys.path.append('..')

from madn import madn
from wtuk import wtuk

yields: ModuleNotFoundError: No module named 'madn

import sys
sys.path.append('..')

from Auxi.madn import madn
from Auxi.wtuk import wtuk

yields: ModuleNotFoundError: No module named 'Auxi'

import sys
sys.path.append('../Auxi/')

from Auxi.madn import madn

yields: ModuleNotFoundError: No module named 'Auxi'

import sys
sys.path.append('.../Auxi/')

from AuxiliaryFunctions.madn import madn

still cannot find Auxi.

I tried it beforehand with a flat structure (all scripts in the same directory) and it worked.

  • Try adding a `print` for `__name__` and `__package__` in each of the imported files. Might shed some light on what's going on – rdas May 11 '19 at 13:00
  • Did you try adding your Package folder in PYTHONPATH?https://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH and then importing giving the full path to madn and wtuk – palvarez May 11 '19 at 13:57

0 Answers0