Рет қаралды 26,003
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 (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