Prep Python Project
Contents
Here is how I prepare python projects.
Assuming Python3 is already installed
I uses python3 installed by default via OS package. or brew python3
(But if I have a chance to use conda and the others, I may try)
Create python3 virtual environment
I uses venv module
- Create
venvpython3 -m venv venv - Activate
venvsource venv/bin/activate - Here you have Isolated environment you can experiment, not affecting entire OS.
Install pip and pip-tools
- Upgrade
pipto latest versionpip install --upgrade pip - Install
pip-toolsfor dependencies managementpip install pip-tools - for more information about
pip-toolssee https://pypi.org/project/pip-tools/
Installing libraries
- Create
requirements.infile.django>=2.2,<3.0 - Run
pip-compilepip-compile - You can check
cat requirements.txt# # This file is autogenerated by pip-compile with python 3.10 # To update, run: # # pip-compile # django==2.2.28 # via -r requirements.in pytz==2022.1 # via django sqlparse==0.4.2 # via django - Install libraries using
pip installpip install -r requirements.txt - You can check installed libraries by
pip listPackage Version ---------- ------- build 0.8.0 click 8.1.3 Django 2.2.28 packaging 21.3 pep517 0.13.0 pip 22.2.2 pip-tools 6.8.0 pyparsing 3.0.9 pytz 2022.1 setuptools 59.6.0 sqlparse 0.4.2 tomli 2.0.1 wheel 0.37.1