Python Virtual Environment, Testing & Packaging Notes Python Project Setup – Notes
These notes summarize a clean, professional Python workflow: virtual environments, testing, packaging, and distribution.
1️⃣ Create a Virtual Environment (MANDATORY habit)
Rule: Never install Python libraries globally. One project = one virtual environment.
Create venv python -m venv .sid-python-lab Activate venv
PowerShell
.sid-python-lab\Scripts\Activate.ps1
Git Bash
source .venv/Scripts/activate Deactivate venv deactivate Confirm venv is active Get-Command python Upgrade core tooling (DO THIS FIRST) python -m pip install --upgrade pip setuptools wheel 2️⃣ Project Installation & Testing Setup Install your project in editable mode pip install -e .
Now Python understands:
import sid_python_lab Add testing early (pytest) pip install pytest Freeze dependencies (basic habit) pip freeze > requirements.txt Run tests pytest Verify installed packages pip list 3️⃣ Running Code & Tests Run your code
Always run Python via the interpreter
python src/sid_python_lab/hello.py Run tests with dependencies pip install pytest requests pytest pytest -v Editable install + tests pip install -e . pytest 4️⃣ Build & Install Python Package (Wheel) Install build tool pip install build Build package python -m build
This creates:
dist/ ├── sid_utils-0.1.0-py3-none-any.whl ├── sid_utils-0.1.0.tar.gz Install the wheel (proof it works) pip install dist/sid_utils-0.1.0-py3-none-any.whl Check installed package pip show sid-utils 5️⃣ Upload Package to Artifactory / Private PyPI Install upload tool pip install twine Configure credentials %USERPROFILE%.pypirc Create file: