From Zero to AI‑Ready: Python on Windows via WSL 2 and VS Code (GitHub + Codex Integration)

From Zero to AI‑Ready: Python on Windows via WSL 2 and VS Code (GitHub + Codex Integration)

Why bother? Because production workloads still lean on Linux, and Windows Subsystem for Linux 2 (WSL 2) lets you run a full kernel without giving up Windows’ desktop conveniences. Follow this playbook and you’ll be writing, testing, and committing AI‑infused Python in under an hour—no VM gymnastics required.


Prerequisites at a Glance

ToolMinimum VersionWhy You Need It
Windows 10 2004 / Windows 11with WSL 2Provides the real Linux kernel
Ubuntu 22.04 LTSor newerStable, long‑term support
VS Code 1.90 +Editor with first‑class WSL remote support
Git 2.40 +Version control muscle memory
GitHub account & SSH keyPasswordless pushes
OpenAI API keyFuel for Codex AI and GitHub Copilot

1  Enable WSL 2 and Install Ubuntu

Open PowerShell as Administrator and run:

wsl --install                 # Installs WSL + default Ubuntu distro
wsl --set-default-version 2   # Make all future distros WSL 2

Reboot when prompted.

Sanity check:

wsl --status                  # Kernel ≥ 5.x, Default = 2

2  Update and Harden the Linux Side

Launch Ubuntu from the Start Menu:

sudo apt update && sudo apt dist-upgrade -y
sudo apt install -y build-essential python3 python3-pip python3-venv git

Need multiple Python versions? Install pyenv the reliable way:

curl https://pyenv.run | bash
# Follow the shell‑config instructions printed to the terminal

3  Wire VS Code into WSL

  1. Install VS Code for Windows (normal installer).

  2. Launch VS Code → Ctrl+Shift+X → install Remote — WSL.

  3. Back in Ubuntu:

    mkdir -p ~/code/my-python-project
    cd ~/code/my-python-project
    code .                     # VS Code opens inside WSL context

    The status bar should now read “WSL: Ubuntu”.


4  Bootstrap a GitHub Repository (Properly)

  1. Generate an SSH key inside WSL:

    ssh-keygen -t ed25519 -C "your.email@example.com"
    cat ~/.ssh/id_ed25519.pub   # Copy the public key
  2. Add the key to GitHub → Settings → SSH and GPG keys.

  3. Create a blank repo on GitHub (no README/LICENCE).

  4. Clone into WSL:

    git clone git@github.com:your‑org/my-python-project.git ~/code/my-python-project
    cd ~/code/my-python-project
  5. First commit:

    python3 -m venv .venv && source .venv/bin/activate
    echo "# My Python Project" > README.md
    echo -e "venv/\n__pycache__/" > .gitignore
    git add README.md .gitignore
    git commit -m "chore: initial commit"
    git push -u origin main

Rule of thumb: keep your SSH keys in WSL, not in the Windows ssh-agent—safer separation.


5  Add Codex AI to Your Workflow

5.1  Install Node 18 LTS & the Codex CLI

Inside WSL:

# Install Node via the Node Version Manager (nvm)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install --lts      # e.g. Node 18.x
nvm use --lts

# Install Codex CLI globally
npm install -g @openai/codex
codex --version        # should echo a semver like 0.2.x

5.2  Authenticate

export OPENAI_API_KEY="<your‑key>"   # add the line above to ~/.bashrc for permanence

5.3  First Run & Modes

cd ~/code/my-python-project
codex "Explain this repo to me."


By default Codex runs in Suggest mode (read‑only). Use --auto-edit to let it write files, or --full-auto for an autonomous agent that can run shell commands inside a sandbox. citeturn0search0

5.4  (Optional) Python SDK

If you also want to call the API directly from scripts:

pip install --upgrade openai

The same OPENAI_API_KEY environment variable is reused.


6  Commit the AI Helpers (Without Leaking Keys)

# Requirements
echo "# AI helpers\nopenai>=1.0" > requirements.txt
pip freeze --local > requirements.lock

git add requirements.txt requirements.lock codex_smoketest.py
# Double‑check no key files are staged
if git status | grep -q api_key; then echo "✗ Key leak detected"; exit 1; fi

git commit -m "feat: add OpenAI Codex integration"

git push

7  Best Practices Going Forward

  • One virtual environment per repo—time‑honoured and still right.

  • Use pre‑commit hooks for black, ruff, and isort.

  • Tune WSL filesystem performance: create /etc/wsl.conf inside Ubuntu:

    [automount]
    options = "metadata,umask=22,fmask=11"

    Then wsl --shutdown from PowerShell to reload.

  • CI/CD parity: GitHub Actions’ ubuntu‑latest runner mirrors WSL—build once, run everywhere.


Conclusion

With WSL 2, Ubuntu, VS Code, GitHub, and Codex AI all humming together, you’ve fused a decades‑proven Linux toolchain with tomorrow’s AI‑driven coding assistants—without ever leaving Windows. Time to ship something awesome.

Comments

Popular Posts