|
|
14 timmar sedan | |
|---|---|---|
| README.md | 14 timmar sedan |
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 build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libsqlite3-dev libffi-dev
Download Python 2.7.3 source code:
cd /usr/src
wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
Extract the downloaded file:
tar -xzf Python-2.7.3.tgz
cd Python-2.7.3
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
Adding Python 2.7 to PATH:
To use the python2.7 command without typing the full path every time:
```bash
echo 'export PATH="/usr/local/python2.7/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
```
**Verify:**
```bash
python2.7 -V
```
pip for Python 2.7Install curl if not installed:
sudo apt install curl -y
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.