TECHNOLOGIESTieInn Technologies

Project setup: virtual environments, requirements, .env files and Git

Python for AI Apps · 10 questions

Short notes

Key idea

Every project gets its own virtual environment, a pinned list of dependencies, secrets in a .env file that never reaches Git, and version control from the first day.

Syntax

python -m venv .venv
.venv\Scripts\activate          # Windows; source .venv/bin/activate on Mac/Linux
pip install google-genai pydantic python-dotenv
pip freeze > requirements.txt
git init

.gitignore:

.venv/
.env
__pycache__/
from dotenv import load_dotenv
load_dotenv()                   # reads .env into environment variables

Example

A teammate clones the repo, creates a venv, runs pip install -r requirements.txt, copies .env.example to .env and fills in their own key. The app runs the same on both machines.

Traps

  • Installing into the global Python mixes projects' versions and breaks one when you update another.
  • Committing .env once leaks the key forever in Git history; rotate it.
  • Unpinned packages change underneath you; pin versions.
  • Commit .env.example with dummy values so others know what's needed.

Want the full lesson with step-by-step examples, a project and a certificate? Python for AI Apps course, ₹180 →

Questions

Open in Code Lab5 free questions
5 questions

    Project setup: virtual environments, requirements, .env files and Git

  1. Question 1easy

    Why create a virtual environment for each project?

  2. Project setup: virtual environments, requirements, .env files and Git

  3. Question 2easy

    What does pip freeze > requirements.txt do?

  4. Project setup: virtual environments, requirements, .env files and Git

  5. Question 3medium

    What does this print?

    import os
    os.environ["MAX_OUTPUT_TOKENS"] = "400"
    value = os.environ.get("MAX_OUTPUT_TOKENS", "300")
    print(value + "0", int(value) + 100)
  6. Project setup: virtual environments, requirements, .env files and Git

  7. Question 4easy

    Which file should be in .gitignore?

  8. Project setup: virtual environments, requirements, .env files and Git

  9. Question 5medium

    You accidentally pushed your API key to GitHub and then deleted the file in a new commit. Is that enough?

5 more questions on this topic, with hints, and tests

Sign up free for 21 days of every question and test.