Consider this simple folder structure:
root
Package1
x.py
y.py
Package2
z.py
Examples
main.py
Now our requirements a
As always, there are two separate steps:
package1 and package2 (and sys, os, etc.), but not “Examples” which is not a package (because main.py is not a module).sys.path appropriately before any of your code ever runs. If it's your own (uninstalled) code, there are places you can put it, or you can write an easy shell script wrapper to set PYTHONPATH for your python process.So the answers to your questions are
x.py you write from . import y. (Python 2 supports this and 3 requires it.)sys.path depends on your packaging/environment system. The traditional way is to set the PYTHONPATH environment variable for the python process, but there are other ways involving things like the site module.from package1 import y is the usual way to name things only once.