My Project has this file Structure:
src
├── API
│ ├── API.py
│ └── __init__.py
├── DataBase
│ ├── CreateDB.py
│ ├── DB.py
│ ├── SpacyTags.py
│ ├── __init__.py
├── ML
│ ├── FeaturePipe.py
│ ├── Labeler.py
│ ├── Predictor.py
│ ├── Transformer.py
│ ├── ModelCreator.py
│ ├── ModelOptimizer.py
│ └── __init__.py
├── News
│ ├── CNBCSpider.py
│ ├── CNBC_parse_article.py
│ ├── HistNewsAPI.py
│ ├── NewsListener.py
│ ├── __init__.py
│ └── new_article_funcs.py
├── Stock
│ ├── HistStockAPI.py
│ ├── ISIN.py
│ ├── PortfolioListener.py
│ ├── UpdateEntries.py
│ ├── __init__.py
├── Testing
│ └── ArticleFeatureTesting.ipynb
├── Exceptions.py
├── __init__.py
├── config.py
└── main.py
Before I ran my program via Pycharm and used imports like this (example from ModelCreator.py):
from src.ML.Labeler import Labeler
from src.ML.ModelOptimizer import optimize_model
from src.Stock.ISIN import ISIN_LIST
Now, that I am migrating to my Raspberry Pi I am unsure how to import for example src/config.py in src/DataBase/DB.py. I still want to be able to run main.py, which is basically importing most of the modules and submodules, while also being able to run the submodules on their own for testing. I also don't like the idea of adding a
import sys
sys.path.append(xyz)
to every file. So I was wondering if there is a cleaner option, which allows all of this.
I've tried to use relative paths for the import, but this led to errors like
ImportError: attempted relative import beyond top-level package
most of the solutions I found didn't work for me, because I want to be able to import my modules in main.py, but still want to run them on their own. Thanks in advance.