部署Python3.6+Django1.11应用时遇pip._vendor.requests无Session属性错误
AttributeError: module 'pip._vendor.requests' has no attribute 'Session' in Python 3.6/Django 1.11 Deployments Hey there, let’s tackle this frustrating error you’re hitting during your code push. That AttributeError with pip._vendor.requests.Session almost always boils down to a broken or mismatched pip/requests setup in your deployment environment—especially since you’re working with older (but still valid) versions like Python 3.6 and Django 1.11.
Common Causes
- Outdated/Mismatched Pip Version: Python 3.6 is no longer supported by newer pip releases (pip 21.0.1 is the last version compatible with 3.6). If your deployment environment auto-upgraded pip to a version that doesn’t support 3.6, it can break the internal
pip._vendor.requestsmodule. - Corrupted Pip Cache/Dependencies: Over time, cached pip files can get corrupted, leading to missing attributes in the bundled requests library.
- Accidental Modification of Pip’s Internal Dependencies: If your deployment scripts or code accidentally touches
pip._vendor.requests, it can disrupt pip’s internal functionality.
Step-by-Step Fixes
Pin Pip to a Compatible Version
Since Python 3.6 can’t handle pip versions newer than 21.0.1, force-install this specific version in your deployment environment:python3.6 -m pip install --upgrade pip==21.0.1Clear Corrupted Pip Cache
Wipe out old cached files to eliminate any corrupted dependencies:python3.6 -m pip cache purge rm -rf ~/.cache/pipReinstall Project Dependencies
Force a fresh install of your requirements to ensure all packages align with your Python/pip setup:python3.6 -m pip install -r requirements.txt --force-reinstallCheck Deployment Scripts
Double-check any deployment hooks or scripts you’re using—make sure none of them are modifyingpip._vendor.requestsor installing conflicting versions of requests alongside pip’s internal copy.Reset Deployment Environment Cache
If you’re using a platform like Heroku, AWS Elastic Beanstalk, or similar, look for an option to clear the build cache before pushing your code again. This ensures the environment starts fresh with your fixed pip setup.
After trying these steps, re-push your code—the error should be resolved.
内容的提问来源于stack exchange,提问作者Rohit Dhankar

