|
|
11 月之前 | |
|---|---|---|
| README.md | 11 月之前 |
Ubuntu 24.04 does not include Python 2.7 by default, as it has reached its end of life. However, if you need it for legacy applications, you can install it by compiling from source.
Update the system packages:
sudo apt update && sudo apt upgrade
Install required dependencies:
sudo apt install -y build-essential checkinstall libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev
Download Python 2.7.18 source code:
cd /usr/src
sudo wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
Extract the downloaded file:
sudo tar xzf Python-2.7.18.tgz
cd Python-2.7.18
Configure and compile Python 2.7:
sudo ./configure --enable-optimizations
sudo make altinstall
Verify installation:
python2.7 -V
Expected output:
Python 2.7.18
pip for Python 2.7Install curl if not installed:
sudo apt install curl
Download the get-pip.py script:
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
Run the script using Python 2.7:
sudo python2.7 get-pip.py
Verify pip installation:
pip2.7 --version
Python 2 is deprecated and no longer maintained. It is recommended to transition to Python 3 for ongoing support and security updates.