VSCode中使用AWS Toolkit调试Python Lambda函数时遇到debugpy依赖解析失败问题求助
Hey there! Let's get this sorted out for you—since you're new to Python Lambda, I'll start with a quick breakdown of what's going on, then walk you through actionable fixes.
First, what is debugpy?
debugpy is the Python debugging tool that AWS Toolkit uses to run and debug your Lambda functions locally. Think of it as the equivalent of the debugging tools you relied on for Node.js Lambda—it lets VS Code attach a debugger to your running Python function so you can step through code.
Why are you seeing this error?
The error PythonPipBuilder:ResolveDependencies - {debugpy==1.5.0(wheel)} means the SAM CLI (which AWS Toolkit uses under the hood) can't install the debugpy==1.5.0 package when building your Lambda environment. This usually stems from version mismatches, network issues, or corrupted cached build files.
Step-by-step fixes to try:
Match your local Python version to Lambda's runtime
Lambda supports specific Python versions (like 3.8, 3.9, 3.10). If your local Python version is too different from what you've set for your Lambda,debugpymight fail to install. Check your local version with:python --version # Or python3 --version on macOS/LinuxMake sure this matches the runtime defined in your
template.yaml(e.g.,runtime: python3.9).Manually specify a compatible debugpy version in requirements.txt
AWS Toolkit automatically addsdebugpyto your dependencies during debugging, but the default 1.5.0 version might not play nice with your setup. Add this line to yourrequirements.txtto force a more compatible version:debugpy>=1.6.0This tells SAM to install a newer, more widely supported release of
debugpy.Clear AWS Toolkit's build cache
Temporary build files can get corrupted over time. Delete the cached directory mentioned in your error:C:/path_to_user/AppData/Local/Temp/aws-toolkit-vscode/vsctkYP3zOS/Then try running the debugger again—SAM will rebuild the environment from scratch, which often fixes weird dependency glitches.
Update AWS Toolkit and SAM CLI
Outdated versions of the toolkit or SAM CLI can cause dependency resolution bugs:- In VS Code, go to the Extensions tab, find AWS Toolkit, and click "Update".
- Update SAM CLI by running
pip install --upgrade aws-sam-cli(works on most systems).
Install debugpy locally first
Try installing the problematic version directly in your local Python environment to rule out installation issues:pip install debugpy==1.5.0If this fails, it might point to a network problem (like blocked access to PyPI). In that case, configure a PyPI mirror (e.g., a regional mirror) via a
pip.conf(Linux/macOS) orpip.ini(Windows) file to bypass restrictions.
Bonus tip: Use a virtual environment
For Python projects, always use a virtual environment to isolate dependencies and avoid conflicts with global packages. Create one with:
python -m venv .venv # Activate it: # Windows: .venv\Scripts\activate # macOS/Linux: source .venv/bin/activate
内容的提问来源于stack exchange,提问作者MountainBiker

