|
|
há 16 horas atrás | |
|---|---|---|
| Python-2.7.18.tgz | há 16 horas atrás | |
| README.md | há 16 horas atrás | |
| get-pip.py | há 17 horas atrás |
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 and upgrade all system packages (YES to all):
sudo apt update && sudo apt upgrade -y
Install required dependencies:
sudo apt install -y build-essential zlib1g-dev checkinstall libncurses5-dev libncurses-dev libnss3-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev libreadline-dev libdb-dev
Download Python 2.7.18 source code:
cd /usr/src
wget https://repo.yosoyhendrix.com/yosoyhendrix/Python-2.7/raw/main/Python-2.7.18.tgz
Extract the downloaded file:
tar xzf Python-2.7.18.tgz
cd Python-2.7.18
Configure and compile Python 2.7: When configuring the build, you have two options for the compilation:
Option 1: Standard Build (Recommended for simplicity)
This option compiles Python without advanced optimizations, resulting in a cleaner and faster build process. By using --prefix=/usr/local/python2.7, you ensure the Python 2.7 executable is installed as /usr/local/python2.7/bin/python. This can avoid overwriting or conflicting with files belonging to the system's default Python 3 installation, potentially breaking system utilities that rely on Python 3.
./configure --prefix=/usr/local/python2.7
make
sudo make install
Option 2: Optimized Build (For potential performance gains)
The --enable-optimizations flag enables Profile-Guided Optimization (PGO), which can result in a slightly faster interpreter.
Note: This could increase the compile time and will produce a large amount of verbose output, including warnings/logs, during the make step.
./configure --enable-optimizations --prefix=/usr/local/python2.7
make
sudo make install
Verify installation:
/usr/local/python2.7/bin/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://repo.yosoyhendrix.com/yosoyhendrix/Python-2.7/raw/main/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.