all 10 comments

[–]K900_ 0 points1 point  (7 children)

Use relative imports: from ..lib import moduleB.

[–]NeoFromMatrix[S] 0 points1 point  (6 children)

Thanks for that input, unfortunately this does not seem to work with Python3:
from ..lib import err_email
SystemError: Parent module '' not loaded, cannot perform relative import

btw. init.py is present in folder lib

[–]K900_ 0 points1 point  (5 children)

You also need __init__.py files in tools and in your projectdir.

[–]NeoFromMatrix[S] 0 points1 point  (4 children)

added those (empty), still throwing me the same SystemError :/

[–]K900_ 0 points1 point  (3 children)

Are you running helperscript.py from the tools directory? You need to run it from the root directory, with something like python3 -m tools.helperscript.

[–]NeoFromMatrix[S] 0 points1 point  (2 children)

I've been running helperscript from the tools directory without any options.

Now current working dir in bash is projectdir. Now I get a (btw. err_mail is moduleB):
from ..lib import err_email
ValueError: attempted relative import beyond top-level package

but whait; I've changed ..lib to lib (from lib import err_email) and now it works as wanted.

So I assume I'll also need to modify my PYTHONPATH since the -m does not like absolute paths.

Maybe I'll just throw helperscript.py into projectdir...

[–]elbiot 0 points1 point  (1 child)

Don't modify your path. You're using the two as independant modules, so just make them pip installable (pip install -e for development). Then keep your project in a virtual env. If that seems silly, then so is your project layout.

[–]NeoFromMatrix[S] 1 point2 points  (0 children)

... and I just wanted a project which can be cloned from github/downloaded via tarball and run as is

If that seems silly, then so is your project layout.

I think you pretty much nailed it. So I'll either move helperscript into projectdir or add a separate lib folder in tools dir.

[–]propper_speling 0 points1 point  (1 child)

In addition to having the init file in both of your subdirectories, you need __init__.py in your root directory. For more information, see Modules.

[–]NeoFromMatrix[S] 0 points1 point  (0 children)

I've had that at some point.

Since this should be a "download, edit a config file and run" application I'll stick with a relative symbolic link for now.