为何我的Python部署包包含大量文件夹?AWS Lambda部署疑问
Great question! Let’s break down exactly why those folders are showing up—and why they’re all necessary for your Lambda function to run:
1. The core dependency chain of requests
The requests library isn’t a standalone tool—it relies on several smaller, specialized packages to handle critical parts of HTTP communication. When you run pip install requests -t /path/to/project-dir, pip automatically pulls in all these transitive dependencies because requests can’t function without them:
urllib3: Manages HTTP connections, retries, and SSL/TLS handshake logicchardet: Detects the character encoding of web responses so your code can parse text correctlycertifi: Provides a trusted set of SSL certificates to verify secure connectionsidna: Handles internationalized domain names (like ones with non-Latin characters)
Since AWS Lambda’s Python runtime doesn’t include these third-party packages by default, you have to bundle them all with your deployment package. Leave any out, and your function will throw a ModuleNotFoundError when trying to run.
2. What the *-dist-info folders do
Those matching *-dist-info directories aren’t just clutter—they’re metadata folders created by pip for every installed package. They contain essential information like:
- Exact package version numbers
- Lists of required dependencies
- Installation configuration details
- Entry points for command-line tools
Lambda uses this metadata to correctly resolve and load the packages at runtime. Even though they don’t have executable code, removing them can break dependency resolution or cause unexpected import failures—which is why you saw errors when missing any of them.
This isn’t unique to Lambda, by the way—this is standard behavior for Python’s package manager. Anytime you install a package to a local directory with pip, you’ll see these same folders and files. Lambda just requires the full, unmodified installation structure to run your code reliably.
内容的提问来源于stack exchange,提问作者Tim 222

