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.

0 Answers