When you run:
export ADURL=https://example.com
export ADU=username
export ADP=password
python -m google.adk.server.app_server 8080It works in the terminal because the shell passes environment variables to the Python process.
But when you debug in VS Code (press F5), VS Code runs Python in a separate process that:
- Doesn't inherit your terminal's environment variables
- Has its own isolated environment
- Only gets variables from:
.envfile (if configured)launch.jsonenvsection- System-wide environment variables (not shell exports)
Terminal Session:
┌─────────────────────────┐
│ export ADURL=... │ ← Sets variable in THIS shell
│ python -m app_server │ ← Inherits from shell ✅
└─────────────────────────┘
VS Code Debugger:
┌─────────────────────────┐
│ Press F5 │
│ │
│ VS Code → Python │ ← Separate process
│ (No shell variables) │ ← Doesn't see export ❌
└─────────────────────────┘
VS Code can automatically load .env file:
- Create
.envin project root - Add variables:
ADURL=https://example.com ADU=username ADP=password - VS Code loads it automatically (via
envFilein launch.json)
Why this works:
- VS Code reads
.envfile directly - No need to export in terminal
- Works for both debugging AND terminal
Add to .vscode/launch.json:
"env": {
"ADURL": "https://example.com",
"ADU": "username",
"ADP": "password"
}Why this works:
- VS Code passes these directly to the debug process
- Works for debugging
Add to ~/.zshrc or ~/.bashrc:
export ADURL=https://example.com
export ADU=username
export ADP=passwordWhy this partially works:
- ✅ Works for terminal:
python -m app_server - ❌ Doesn't work for VS Code debugging (unless you restart VS Code after setting)
⚠️ VS Code only reads system environment on startup
In .vscode/settings.json:
{
"terminal.integrated.env.osx": {
"ADURL": "https://example.com",
"ADU": "username",
"ADP": "password"
}
}Why this partially works:
- ✅ Works for VS Code terminal
- ❌ Doesn't work for debugging (debugger uses different process)
| Method | Terminal Run | VS Code Debug | Notes |
|---|---|---|---|
export in terminal |
✅ Yes | ❌ No | Only in that shell session |
.env file |
✅ Yes* | ✅ Yes | *If using python-dotenv |
launch.json env |
❌ No | ✅ Yes | Only for debugging |
Shell profile (~/.zshrc) |
✅ Yes | Only if VS Code restarted |
- Separate Process: Debugger runs
debugpywhich spawns Python in a new process - Isolated Environment: Doesn't inherit from your terminal session
- Security: Intentionally isolated to prevent environment pollution
Use .env file because:
- ✅ Works for both terminal and debugging
- ✅ Easy to manage
- ✅ Can be gitignored (keeps secrets safe)
- ✅ Standard practice
To verify what VS Code sees:
Add this to your code temporarily:
import os
print("ADURL:", os.getenv('ADURL', 'NOT SET'))
print("ADU:", os.getenv('ADU', 'NOT SET'))
print("ADP:", os.getenv('ADP', 'NOT SET'))Run in:
- Terminal:
python -m google.adk.server.app_server 8080→ Should show values if exported - VS Code Debugger (F5): → Will show "NOT SET" unless you use
.envorlaunch.json
export doesn't work with VS Code debugging because:
- VS Code debugger runs in a separate process
- It doesn't inherit your terminal's environment
- It only reads from
.envfile orlaunch.jsonenv section
Solution: Use .env file - it works for both terminal and debugging!