Prep Python Project

Here is how I prepare python projects.

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)

I uses venv module

  • Create venv
    1
    
    python3 -m venv venv
    
  • Activate venv
    1
    
    source venv/bin/activate
    
  • Here you have Isolated environment you can experiment, not affecting entire OS.
  • Upgrade pip to latest version
    1
    
    pip install --upgrade pip
    
  • Install pip-tools for dependencies management
    1
    
    pip install pip-tools
    
  • for more information about pip-tools see https://pypi.org/project/pip-tools/
  • Create requirements.in file.
    1
    
    django>=2.2,<3.0
    
  • Run pip-compile
    1
    
    pip-compile
    
  • You can check cat requirements.txt
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    
    #
    # 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
    1
    
    pip install -r requirements.txt
    
  • You can check installed libraries by pip list
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    
    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
    

Related Content