杰瑞科技汇

Python 2.7.13 RPM包如何下载安装?

Of course. Finding and installing Python 2.7.13 RPMs requires understanding the specific Linux distribution you are using, as repositories and package management vary.

Python 2.7.13 RPM包如何下载安装?-图1
(图片来源网络,侵删)

Here’s a comprehensive guide covering the most common scenarios, from modern systems to legacy ones.

⚠️ Important Security and Compatibility Warning

Python 2.7 reached its official "end-of-life" on January 1, 2025. This means:

  • No Security Updates: It no longer receives security patches. Running it in production is a significant security risk.
  • No Bug Fixes: Critical bugs will not be fixed.
  • No Standard Library Updates: You cannot use modern Python packages that require features from Python 3.6+.

Strong Recommendation: The best course of action is to migrate your applications to a supported version of Python 3. This guide is provided for legacy system maintenance, not for new development.


Option 1: For RHEL / CentOS 7 (Using Software Collections)

This is the recommended and safest method for running a specific version of Python on a modern system like RHEL/CentOS 7 without conflicting with the system's default Python 2.7. The softwarecollections.org (SCL) repository provides well-built, supported RPMs.

Step 1: Enable the SCL Repository

First, you need to enable the correct repository. For RHEL/CentOS 7, this is the rhel-server-rhscl-7-rpms repository.

# For CentOS 7
sudo yum install centos-release-scl
# For RHEL 7, you may need to enable the repository via subscription manager
# or ensure you have the 'rhel-server-rhscl-7-rpms' channel enabled.

Step 2: Install the Python 2.7 Collection

The collection for Python 2.7 is called rh-python27. You can install the base package, which includes the interpreter and common libraries.

sudo yum install rh-python27

Step 3: Activate and Use Python 2.7

The Python interpreter is not in your standard $PATH by default. You must "activate" the collection.

# Activate the collection for your current shell session
scl enable rh-python27 bash
# Verify the version
python --version
# Expected output: Python 2.7.13 (or a later patch version in the 2.7 series)
# To check where the executable is located
which python
# Expected output: /opt/rh/rh-python27/root/usr/bin/python

To make it permanent for a user, add this to their ~/.bashrc or ~/.bash_profile:

# Add this line to the end of the file
source /opt/rh/rh-python27/enable

To install Python packages (like pip or virtualenv) for this version:

scl enable rh-python27 "pip install <package_name>"
# Example: scl enable rh-python27 "pip install virtualenv"

Option 2: For Older RHEL / CentOS 6 (Using EPEL and SCL)

CentOS 6's default repositories have older software. You'll need the EPEL repository and SCL.

Step 1: Enable EPEL and SCL Repositories

# Install the EPEL release package
sudo yum install epel-release
# Enable the SCL repository for CentOS 6
sudo yum install centos-release-SCL

Step 2: Install Python 2.7

The package name is simply python27.

sudo yum install python27

Step 3: Use Python 2.7

The interpreter will be installed to /usr/bin/python27.

# Check the version
python27 --version
# Expected output: Python 2.7.13

You can create a symbolic link if needed, or just call the executable directly (python27).


Option 3: For Fedora (Using dnf and the Copr Repository)

Fedora's default repositories move very quickly and will not have Python 2.7. The best way to get it is from a third-party repository like Copr.

Step 1: Install dnf (if not already present) Fedora 22+ uses dnf. Older versions used yum.

Step 2: Enable the Copr Repository

This repository provides a well-maintained Python 2.7 build.

sudo dnf copr enable @python/python27

Step 3: Install Python 2.7

sudo dnf install python27

Step 4: Use Python 2.7

The executable will be python27.

python27 --version
# Expected output: Python 2.7.13

Option 4: Manual Installation from Source (The Last Resort)

If no pre-built RPM is available for your specific system architecture or configuration, you can compile Python 2.7.13 from source and create your own RPM. This is an advanced process.

Prerequisites: You'll need the "Development Tools" group and other required libraries.

# For RHEL/CentOS/Fedora
sudo yum groupinstall "Development Tools"
sudo yum install openssl-devel bzip2-devel zlib-devel gdbm-devel readline-devel sqlite-devel ncurses-devel xz-devel tk-devel

Step 1: Download the Source Code Get the source tarball from the Python website.

wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
tar -xzf Python-2.7.13.tgz
cd Python-2.7.13

Step 2: Configure and Compile It's highly recommended to install Python to a custom prefix (e.g., /usr/local/python2.7) to avoid conflicts.

# Configure the build
./configure --prefix=/usr/local/python2.7 --enable-optimizations
# Compile (this will take a few minutes)
make -j$(nproc) # Use all available cores for a faster build

Step 3: Install

sudo make altinstall
# Note: Use `make altinstall` to prevent it from overwriting your system's `python` symlink.

Step 4: Verify the Installation

/usr/local/python2.7/bin/python --version
# Expected output: Python 2.7.13

To create an RPM from this source installation, you would use the rpmbuild tool, which is a much more complex process involving creating a .spec file. This is generally only necessary if you need to package the software for distribution to many identical machines.

Summary Table

Distribution Recommended Method Command / Key Packages Notes
RHEL/CentOS 7 Software Collections (SCL) yum install centos-release-scl, yum install rh-python27 Safest method. Isolates Python from the system. Use scl enable.
RHEL/CentOS 6 EPEL + SCL yum install epel-release, yum install python27 Uses older, but stable, packages. Executable is python27.
Fedora Copr Repository dnf copr enable @python/python27, dnf install python27 Uses a community-maintained repository. Executable is python27.
Any Linux Manual Source Install ./configure && make && sudo make altinstall Last resort. Full control, but complex. No RPM management.
分享:
扫描分享到社交APP
上一篇
下一篇