0122-better way to use my own code
Better way to manage my python code
1. Organize Your Code as a Python Package
my_project/
โโโ my_package/ # Your actual Python code
โ โโโ __init__.py # Makes this directory a package
โ โโโ module1.py # Your code files
โ โโโ module2.py
โโโ scripts/ # Scripts using your package
โ โโโ run_analysis.py
โโโ tests/ # Unit tests
โ โโโ test_module1.py
โโโ setup.py # Installation script
โโโ pyproject.toml # Modern build configuration (optional)
โโโ requirements.txt # Dependencies (if any)
โโโ README.md2. Write a setup.py for Easy Importing
setup.py for Easy ImportingDifference between ` pip install -e . `and `pip install .`
1. pip install . (Regular Installation)
pip install . (Regular Installation)2. pip install -e . (Editable Installation)
pip install -e . (Editable Installation)Comparison Table
Which One Should You Use?
Use pyproject.toml or setup.py?
Advantages of pyproject.toml Over setup.py
pyproject.toml Over setup.py1. Future-Proof and PEP 517/518 Compliant
2. No Need for setup.py Execution
setup.py Execution3. Cleaner and More Readable
Using setup.py
setup.pyUsing pyproject.toml
pyproject.toml4. Easier Dependency Management
5. Works with Modern Build Tools
Should You Switch?
Last updated