D. Python Environment Setup

  • On GitHub, new a project and choose Python.gitignore

  • Git clone the new project with a token, which gives you permission to push

  • In vs code, go to File > Open Folder to open the project

Manual

  • python -m venv .venv in the project root to create a virtual environment called .venv

    • A virtual environment is a folder for an independent python.exe and its own site-packages which this python.exe can import from

    • venv is part of the python standard library

    • -m is to run a module, venv in this case

  • .venv\Scripts\activate to activate the virtual environment to start use the independent python.exe

  • Create a requirements.txt file in the project root to keep a list of all packages (and possibly versions) you want to use

  • pip install -r requirements.txt to pip install packages from the list

uv

  • uv init in the project root to initialize the project

    • It creates a pyproject.toml file amoung others

    • pyproject.toml is the recommended replacement of requirements.txt. Other package managers (e.g. poetry) will also give you a pyproject.toml file

  • uv sync to create and sync the venv as defined in pyproject.toml

    • You still need to manually run .venv\Scripts\activate activate the virtual environment

    • Or you can choose the project venv in vs code at the bottom right corner. Once done, vs code will activate the venv automatically every time you start a new command prompt

  • uv add numpy to add numpy to pyproject.toml and to the venv

  • uv remove numpy to remove numpy from pyproject.toml and from the venv

  • Try not to edit pyproject.tmol manually; Do it through uv

  • Install python version

    • uv venv --python 3.12.4

    • uv python install 3.12.4

Git

  • Download Git and install

  • git init in the project root to version control the project by Git

  • Create a .gitignore file in the project root

    • Copy the contents of Python.gitignore and paste in yours

    • The same repo has recomended .gitignore in other languages/type of projects

  • git add * to add current code changes to the staging area

    • The staging area is an intermediate space to keep the changes before you commit

  • git commit -m "YOUR_COMMIT_MESSAGE"

    • Commit message is required

  • Configure Git username and email

    • git config --global user.name "YOUR_NAME"

    • git config --global user.email "your_email@example.com"

    • Please use the same username and email as your GitHub account

VS Code

  • Install the Python extension

  • Open a .py file and look at the bottom right, VS Code should be aware of the venv. Kill the terminal and open a new one and the venv will be activated automatically

  • Keyboard shortcut

    • Ctrl + Shift + G: Focus version control tab on the left

    • Ctrl + Shift + E: Focus file explorer on the left

    • Ctrl + 1: Focus editor

      • When you are in editor, Ctrl + Page Up/Dn to switch between files

    • Ctrl + Shift + ~: Focus terminal

    • Ctrl + Shift + Y: Focus debug console

    • Ctrl + Shift + I: Focus github copilot chat

Side Project Ideas

GARCH

Numerical Math

  • If we know the point values of a \(C^{\infty}\) function \(f\) at \(a\) and \(a+h\), we can use a linear function

    \[y = f(a) + (x-a)\frac{f(a+h) - f(a)}{h}\]

    to approximate \(f\) in the interval \([a, a+h]\). This is linear interpolation. This approximation has an error bond \(Ch^2\). Can you find me the error bond and its proof?