Thank you very much for this discussion, I understand a lot more abuot the mechanisms behind imports and sys.path and I believe that I can solve or at least work around most issues. However, I think it is a good idea to provide a bit more control about the contents of sys.path.
Would it be possible to add a setting where you can check for each directory in your user space if it has to be included in sys.path?
Dgelessus was right, the directory from which the last script was run is the first entry in sys.path. This inspired the following workaround: put an empty script in the directory from which you want to import. Run it, and the directory is on the path. You can import modules from that directory!
No, Documents is not on the path at all. Strange that we have different paths... I was aware of site-packages but it is much easier to develop in anorher directory and import directly from there. When the module is complete it can be moved to site-packages.
Thanks for the tip about os.path.expanduser! I considered adding a directory to sys.path but typing an absolute path is nearly impossible. Expanduser makes it possible.
These are the directories in sys.path (slghtly edited to remove the prefix from root to app):
Documents itself is not on the path, neither are its subdirectories. Is this a bug? Is it possible to add directories to the path?
Although not at all new to programming, I am new to Python(ista). Let me state upfront that I am really impressed. There are only a few full fledged programming environments for iOS and Pythonista is one of the best. However, I have a few questions.
If I understand correctly there is only little difference between scripts and modules. Both are files with a .py extension. Scipts contain definitions and executable statements (but there are exceptions) and modules contain only definitions (but there are exceptions).
I used the script editor to create a .py file and tried to import it as a module in the interactive prompt. However I get an error message that no module with that name can be found.
How can I define a module and import it in a script or in the interactive prompt?
Thanks for any help!