I have a utils package which provides functions for my (crontab) Python scripts.
The scripts are organized in different directories on the same path:
Eg.:
scripts/client1/process-client1.py
.. /client2/process-client2.py
.. /client3/process-client3.py
.. /utils/foo.py
All of these files live in similar setup in SVN repository (except each has trunk/ and tags/ before actual code, so I export them to production whenever needed)
The modules in utils package should be available to all scripts (the utils package does contain __init__.py
)
I tried relative import, in process-client1.py:
import ..utils
However, obviously I got:
ValueError: Attempted relative import in non-package
Is there any other way? I wouldn't like to utils/ in each client dir, as it is really a common package that is needed by all scripts, and if I make a change in it, it should be reflected in all scripts using it.
It wouldn't sound right also to convert client scripts to packages, as they are really not. Plus, how would that work, I tried putting empty __init__.py
in /scripts/ and /scripts/client*/ dirs, but that didn't help anyway.
I could do symlink for each client to ../utils/, however, this is additional info that needs to be tracked, the clients list is changing and it doesn't sound right (but I expect I might end up doing it anyway).
I looked at As a Java programmer learning Python, what should I look out for? , but this is not really described there. At python source code organization and __init.py__ -- I seem to have similar setup, but I can't import either utils or ..utils from sibling dir?