Let's assume I have two parallel directories, with simple python files.
- 'dir_one' with file_one.py
- 'dir_two' with file_two.py
In file_one.py there is a function named function_one.
How can I import it in file_two.py?
I have checked literally a few dozens of sources, including answers on stackoverflow. Therefore, I am not quoting any of them here. I have tried four different solutions, none of them worked:
- Insert 'init.py' files in all the directories - results in error 'ImportError: attempted relative import with no known parent package'
- Make both directories a single package - not possible in this case, directories have to be able to run as independent apps.
- Use sys module: sys.path.insert(0, 'path-to-dir_one') right before 'import dir_one' line - doesn't change anything, still get 'ModuleNotFoundError: No module named 'dir_one'.
- try relative import: 'from .dir_one import file_one' - 'ModuleNotFoundError: No module named 'zweizen.prodalitics'.
Is it possible at all to import a function in python from parallel folder without making it part of the same package?

dir_oneas a dependency to thedir_twopackage metadata. All modern package managers (uv, Poetry …) should support this, and evenpipdoes. — The upshot is: you would install thedir_onepackage in the environment ofdir_two. You can use an “editable” dependency if you want to be able to see edits todir_one“live” indir_two.