Ubuntu 12.04 LTS无法通过pip安装Python 2包求助(TLS需升级至1.2)
Hey there, let's work through getting your pip working again on Ubuntu 12.04—since you mentioned needing to upgrade TLS from 1.1 to 1.2, that's exactly the root of the problem here. Modern PyPI servers no longer accept TLS 1.1 connections, and your old system + outdated pip are struggling to keep up. Here's how to fix it step by step:
First, a quick heads-up: Ubuntu 12.04 is end-of-life, so its default repositories are no longer active. We'll need to adjust that first to get the necessary updates.
1. Switch to Old-Releases Repositories
Since the standard Ubuntu repos don't serve 12.04 anymore, edit your sources list to use the old-releases mirror:
sudo nano /etc/apt/sources.list
Replace every occurrence of archive.ubuntu.com and security.ubuntu.com with old-releases.ubuntu.com. Save the file (Ctrl+O, Enter) and exit (Ctrl+X). Then update your package index:
sudo apt-get update
2. Upgrade OpenSSL to Support TLS 1.2
Ubuntu 12.04's default OpenSSL version doesn't fully support TLS 1.2. Install the latest available version from the old-releases repo:
sudo apt-get install --only-upgrade openssl libssl-dev
Verify the upgrade worked by checking the version (you need at least 1.0.1g, which adds TLS 1.2 support):
openssl version
3. Upgrade pip to a Version That Works with TLS 1.2
Your pip 1.0 is way too outdated to handle modern TLS requirements. We'll upgrade it to the last version that supports Python 2.7 (pip 20.3.4):
Option 1: Use easy_install (if it's available)
sudo easy_install -U pip==20.3.4
Option 2: Use the pip bootstrap script
If easy_install fails, grab the official pip bootstrap script made for Python 2.7, save it as get-pip.py on your system, then run:
sudo python get-pip.py pip==20.3.4
4. Test the Fix
Try installing a Python 2 package to confirm everything works. Let's use the last Python 2-compatible version of requests:
pip install requests==2.27.1
If this installs without SSL errors, you're good to go!
Bonus: Use a Virtual Environment (Optional)
To keep your system Python clean, consider setting up a virtual environment for your Python 2 projects:
sudo apt-get install python-virtualenv virtualenv py2_project_env source py2_project_env/bin/activate # Now you can install packages here without affecting the system Python pip install requests==2.27.1
内容的提问来源于stack exchange,提问作者Vithulan

