Set Up Your Python App Environment

Follow these simple steps to get started with your Python application.

  1. Install Python (version 3.10 or later):
    • Go to the official website: https://www.python.org/downloads/
    • Click the **"Download Python"** button for your operating system (Windows, macOS, or Linux).
    • Important: On Windows, during installation, make sure to check the box that says "Add Python to PATH" at the bottom of the setup window.
    • Then click **Install Now** and complete the setup.
    This ensures that you can use Python from the command line by simply typing python.
  2. Install Visual Studio Code (VS Code):
    • Download from code.visualstudio.com
    • Launch VS Code after installing.
    • Go to the Extensions sidebar (or press Ctrl+Shift+X), search for Python, and install the extension by Microsoft.
    • Open your project folder in VS Code and select your Python interpreter (.venv/bin/python or .venv\Scripts\python.exe) via the Command Palette (Ctrl+Shift+P -> "Python: Select Interpreter").
  3. Create your project folder:
    mkdir my-app
    cd my-app
  4. Create a virtual environment:
    python -m venv .venv
    source .venv/bin/activate  # macOS/Linux
    .venv\\Scripts\\activate     # Windows
  5. Install essential packages:
    pip install openai langchain faiss-cpu tiktoken chromadb
    Optional (for web app):
    pip install flask flask-cors
  6. Create a .env file:
    OPENAI_API_KEY=your_openai_key_here
  7. Install and configure a vector database (ChromaDB):
    • ChromaDB is a lightweight and easy-to-use vector database for local or cloud storage.
    • Already included if you installed chromadb in step 5.
    • Use persistent storage to retain data between runs:
      import chromadb
      client = chromadb.PersistentClient(path="./chroma-store")
  8. Write your app logic (e.g. app.py):
    You don't need to write everything from scratch. You can ask an LLM like ChatGPT or Copilot to generate the code for you - all you need is the right prompt.

    Try this:
    Write Python code that uses OpenAI API to embed a user query,
    search a ChromaDB vector store for the top 3 relevant documents,
    and then send those results back to GPT-3.5 to generate an answer.

    This approach allows you to focus on what you want to build - not every syntax detail.
  9. Run your app:
    python app.py
  10. Organize your project structure:
    Once you've tested your basic app.py and confirmed it works, it's time to think about organizing your project for long-term development. Before writing serious logic or sharing your work on GitHub, a clean folder structure will make your code easier to scale, maintain, and collaborate on.
    
    my-app/
    +-- app/
    |   +-- api/                  # API route controllers
    |   +-- config/               # config files, etc.
    |   +-- service/             # Core business logic, Emebddings, storage, LLMs
    |   +-- ui/                   # UI-facing logic and assets
    |   |   +-- static/           # JS/CSS/images
    |   |   +-- templates/        # HTML templates
    |   |   `-- app_controller.py  # (UI controller)
    |   +-- util/                # Logger, file utils, etc.
    |   `-- main.py               # [OK] App entry point
    |
    +-- deploy/                   # AWS ECS, AppRunner, etc.
    +-- logs/               # Log files
    +-- test/                    # Pytest test suite
    +-- .dockerignore
    +-- .env                      # Environment config
    +-- .gitignore
    +-- Dockerfile                # For containerization
    +-- README.md
    `-- requirements.txt
            
    This layout helps keep your logic modular and production-ready.