I've been trying to use better project structure for my ML demos, but I keep getting punched in the face by Python when importing sibling packages.
my_ml_project/
run_project.py
sweet_src_code/
models_dir/
amazing_model.py
tests_dir/
beautiful_test.py
I add __init__.py files everywhere, re-read the python docs (https://lnkd.in/gcgeb6qA), and remain utterly confused.
I then usually give up and put everything in the top level dir:
my_ml_project/
run_project.py
amazing_model.py
beautiful_test.py
I finally came across a stack overflow answer that I had previously missed: use a setup.py file.
This video is a quick demonstration of what doesn't work (failing to import my model_dir from a sibling test_dir) and how adding a short setup.py file to the project root fixes the problem.
This is basic stuff but I now feel such relief. No more pentagrams of salt, ritualistic animal sacrifices, and __init__.py files everywhere trying to get imports to work.
If you want to connect with me, I'm most active on LI. Feel free to connect with me: / gustafrcavanaugh
Смотрите видео Adding __init__.py not working - Module Not Found: Fixing Python Sibling Directory Import Error онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Gus Cavanaugh 11 Декабрь 2022, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 31,360 раз и оно понравилось 522 людям.