You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python 2.7提示No module named yum,求针对该环境编译yum的指导

Compiling YUM for Python 2.7 on Oracle Linux

Hey there, let’s work through compiling the yum module specifically for your Python 2.7 installation on Oracle Linux. I’ve gone through similar headaches before, so here’s a practical step-by-step guide to get this sorted:

Step 1: Install Compilation Dependencies

First, make sure you have all the tools and libraries needed to build yum from source. Run this command to install the required packages:

sudo yum install gcc python27-devel rpm-devel openssl-devel libxml2-devel libxslt-devel yum-utils

The yum-utils package gives us yumdownloader, which we’ll use to grab the yum source code.

Step 2: Retrieve YUM Source Code

Download the yum source RPM package for your Oracle Linux version:

yumdownloader --source yum

Once downloaded, extract the source files from the RPM:

rpm2cpio yum-*.src.rpm | cpio -idmv

This will create a directory with all the yum source files and build configurations.

Step 3: Adjust Configurations for Python 2.7

Navigate into the extracted source directory. We need to tweak a few files to make yum target your Python 2.7 installation:

  1. Modify the yum.spec file:
    Open yum.spec in a text editor, and look for lines defining Python paths. Update %define python_sitelib and %define python_sitearch to point to your Python 2.7’s site-packages directory. For 64-bit systems, this is usually:

    %define python_sitelib /usr/lib64/python2.7/site-packages
    %define python_sitearch /usr/lib64/python2.7/site-packages
    

    For 32-bit systems, replace lib64 with lib.

  2. Update shebang lines:
    Check all Python scripts in the source (like yum, yum-config-manager, etc.) and change their shebang from #!/usr/bin/python to #!/usr/bin/python2.7. This ensures they use your target Python version instead of the system default.

Step 4: Build and Install YUM for Python 2.7

Before building, make sure your Python 2.7 has setuptools installed. If not, run:

sudo easy_install-2.7 setuptools

Then, build and install the yum module:

cd path/to/yum-source-directory
python2.7 setup.py build
sudo python2.7 setup.py install

Step 5: Verify the Installation

Test if the yum module is now accessible in Python 2.7:

python2.7 -c "import yum; print('YUM module version:', yum.__version__)"

If this outputs the yum version without errors, you’re good to go!

Important Notes

  • Don’t overwrite the system yum: Your Oracle Linux system likely relies on the default Python version (often 2.6) for system yum operations. Keep the system yum intact, and use your compiled version only for your Python 2.7 scripts.
  • Dependency checks: If you run into import errors after installation, make sure Python 2.7 has all required dependencies like rpm, pycurl, and libxml2 installed. You can install them via pip2.7 if available, or via yum packages built for Python 2.7.

内容的提问来源于stack exchange,提问作者carte blanche

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:32:44