I have the following simplified repo structure:
- project
- src
- config
- config_new.py
- util
- util_new.py
- app
- app_new.py
The app_new.py module looks like the following (it is the core module to be executed via python app_new.py):
from project.src.config.config_new import ConfigClass
from project.src.util.util_new import UtilClass
def func1():
...
if __name__ == "__main__":
func1()
After my old repo had to be closed, I cloned the new repo version into my PyCharm project folder and associated my pre-existing virtual environment with the new repo. However, after cloning, the relative imports do suddenly not work anymore across the repo and the following error is thrown:
from project.config import config_new.py
ModuleNotFoundError: No module named "config_new.py"
I have literally tried anything:
- Cleared PyCharm cache
- Checked interpreter paths
- Inputted init.py files into the root directory and all subdirectories
- Cloned the repo multiple times
- Marked all directories above as source directories
- Experimented with double dots on the relative imports to refer to top-level directories
- Checked this helpful thread and all related threads: Relative imports for the billionth time
As far as I have understood, when using a module with if name == "main":, the relative import is not considered to be in a package. However, I could use this exact setup before cloning the repo again and re-associating the existing virtual environment with it. Is there anything else I might have overlooked? Thanks!