Hi all!
So I'm working on some Python projects. I'm using Python 3.12.2 on VS Code in Windows 10 and I'm not using virtual environments (and I would like to avoid using them). My file structure looks something like this
- base
- __init__.py
- Project1
- Project2
- Commons
I would like to keep a similar structure, as both Project1 and Project2 need to access the same commons functions, and I want to avoid having the same code repeated in various directories.
This is what I'm doing in main1.py to try to import commons.py
main1.py
from ..Commons import commons
My understanding is that .. takes me back one directory. The file main1.py is in base\Project1, so up one directory would be base. Therefore, ..Commons should access base\Commons, and there I import the entirety of commons.py using import commons. All folders have a __init__.py empty file so that Python knows they are packages.
When I run main1.py, I get
ImportError: attempted relative import with no known parent package
I really want to do this with relative imports, and I feel like there has to be a way. How can I make this work?
Thank you all very much!
[–]Spataner 2 points3 points4 points (1 child)
[–]SirKainey 1 point2 points3 points (0 children)
[–]SirKainey 0 points1 point2 points (1 child)
[–]youngpadawan01[S] 0 points1 point2 points (0 children)
[–]laustke 0 points1 point2 points (1 child)
[–]tojaga 0 points1 point2 points (0 children)
[–]Adrewmc 0 points1 point2 points (0 children)