Prep Python Project

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 venv
    python3 -m venv venv
    
  • Activate venv
    source venv/bin/activate
    
  • Here you have Isolated environment you can experiment, not affecting entire OS.

Install pip and pip-tools

  • Upgrade pip to latest version
    pip install --upgrade pip
    
  • Install pip-tools for dependencies management
    pip install pip-tools
    
  • for more information about pip-tools see https://pypi.org/project/pip-tools/

Installing libraries

  • Create requirements.in file.
    django>=2.2,<3.0
    
  • Run pip-compile
    pip-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 install
    pip install -r requirements.txt
    
  • You can check installed libraries by pip list
    Package    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