Introduction
This guide explains how to install the Python package manager pip and the requests module on a CentOS 6.8 64-bit system. Since CentOS 6 is outdated, its default Python environment lacks pip, and many software repositories are no longer available, requiring manual installation of setuptools and pip.
Installation Steps
1. Install setuptools
setuptools is a foundational toolset for Python packages, and pip depends on it. Execute the following commands in order:
wget --no-check-certificate https://files.pythonhosted.org/packages/dc/8c/7c9869454bdc53e72fb87ace63eac39336879eae6e23f1c16d06c0c12864/setuptools-65.6.3.tar.gz
tar zxvf setuptools-65.6.3.tar.gz
cd setuptools-65.6.3
python setup.py build
sudo python setup.py install
Note: The original version (32.1.0) was outdated. This uses a newer, compatible version (65.6.3) with an updated official download link.
2. Install pip
After installing setuptools, proceed to install pip:
wget --no-check-certificate https://files.pythonhosted.org/packages/cd/82/04e9aaf603fdbaecb4323b9e723f13c92c245f6ab2902195c53987848c78/pip-24.0.tar.gz
tar zxvf pip-24.0.tar.gz
cd pip-24.0
sudo python setup.py install
Note: The original pip version (9.0.1) was outdated. This uses version 24.0 with an updated download link.
3. Install the requests module
Once pip is installed, use it to install Python packages. Run the following command to install the requests module:
pip install requests
If your system has multiple Python versions, you may need to use pip2 or specify the full path (e.g., /usr/bin/pip) to ensure installation for the correct Python version.
Verification
After installation, verify that pip and requests are installed correctly:
pip --version
python -c "import requests; print(requests.__version__)"
The first command should output the pip version. The second should output the requests module version number.
Important Notes
- System Compatibility: CentOS 6 reached End of Life (EOL) in November 2020 and is no longer officially supported. Consider upgrading to CentOS 7/8 Stream, Rocky Linux, or AlmaLinux.
- Python Version: CentOS 6.8 may have Python 2.6 by default. If your application requires Python 3, install Python 3 first and use the
python3andpip3commands. - Permissions: Installing system-wide Python packages typically requires
sudoprivileges. If you are working within a virtual environment (virtualenv),sudois not needed. - Network Issues: If downloads are slow or fail, consider using a domestic mirror source (e.g., Tsinghua, Alibaba Cloud) to download the setuptools and pip source packages, or configure a pip mirror.
Modern Alternative
For maintained systems like CentOS 7 or later, pip can often be installed more simply via the system package manager:
# CentOS 7 install pip for Python 2
sudo yum install python-pip
# CentOS 7 install pip for Python 3
sudo yum install python3-pip
# Install the requests module
pip install requests # or pip3 install requests
These commands typically work if the EPEL repository is already installed on the system.