skip to Main Content

Environment: Aws EC2, redhat – centos

While installing awscli, due to incompatibility between awscli2 and python2.6 , I had to install python 3.7. But while doing this i removed all existing python packages including default system usage onces.

Now when I try to execute yum, it gives following error:

/usr/bin/python: bad interpreter: No such file or directory

Then, I installed python2.6 (and also tried 2.7) manually with following way.

sudo wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz 

sudo tar xzf Python-2.7.9.tgz

cd Python-2.7.9

sudo ./configure --enable-optimizations

sudo make & sudo make install

But again it gives same error:

When i change default python directory

sudo vim `which yum`

/usr/local/bin/python2.7 and tried also /usr/local/bin/python2.6

Also for 2.7 I tried adding following

sys.path.append('/usr/local/bin/python2.7/site-packages')
sys.path.append('/usr/lib64/python2.7/site-packages')

But now it gives following error.

No module named yum

3

Answers


  1. I’m not sure if this is a valid answer, but I’ve put a few hours into this and the conclusion is to reinstall the system.

    Other way may possibly be a thorough investigation of all package dependencies, downloading the rpms manually and updating using rpm command, but that is another few hours. Since we are going to reinstall the whole system pretty soon, it’s not a big concern.

    We will use Debian 11, not CentOS. CentOS 7 is really old.

    It needs to be noted that this problem would not occur, if the new Python would be "altinstall"ed instead of "install"ed in the first place.

    Login or Signup to reply.
  2. Well, you know which python it needs (the path) – presumably python 2.6 on your original system:

    /usr/bin/python: bad interpreter: No such file or directory

    And you know where python gets installed into, when built from scratch:

    /usr/local/bin/python2.6

    In general it’s not a good idea to remove your system’s python installation. This is why there are tools like pyenv for instance.

    Back to your problem – You could create an alias for the time being, either temporarily in your shell or persistently in your ~/.bashrc (assuming you use bash):

    alias python='/usr/local/bin/python2.6'
    

    This will, for your user and your session, make python link to /usr/local/bin/python2.6.


    By the way, problems like this:

    No module named yum
    result from the fact that dependencies are installed for specific python versions only, i.e.:

    # This
    python2.6 -m pip install requests
    # installs 'requests' for python2.6 only.
    # That means for python2.7, there is no 'requests' module.
    

    I can only recommend pyenv to manage multiple python versions in your system and a python dependency management tool like e.g. poetry to define dependencies and install them correctly in terms of python version, constraints and dependencies of dependencies.

    Login or Signup to reply.
  3. I meet this issue and i run this bash shell to reinstall yum by execute sh /install/reinstall-yum.sh on Centos 7 (Core). Create Folder and file with conent of reinstall-yum.sh as below:

    #!/bin/bash
    
    ## Download and Reinstall these packages. This will make yum can executed again
    packages=(
        "cpio-2.11-28.el7.x86_64.rpm"
        "diffutils-3.3-5.el7.x86_64.rpm"
        "iniparser-3.1-5.el7.x86_64.rpm"
        "kernel-abi-whitelists-3.10.0-1160.el7.noarch.rpm"
        "pygpgme-0.3-9.el7.x86_64.rpm"
        "pyliblzma-0.5.3-11.el7.x86_64.rpm"
        "python-2.7.5-89.el7.x86_64.rpm"
        "python-devel-2.7.5-89.el7.x86_64.rpm"
        "python-libs-2.7.5-89.el7.x86_64.rpm"
        "python-rpm-macros-3-34.el7.noarch.rpm"
        "python-tools-2.7.5-89.el7.x86_64.rpm"
        "python-urlgrabber-3.10-10.el7.noarch.rpm"
        "python2-rpm-macros-3-34.el7.noarch.rpm"
        "pyxattr-0.5.1-5.el7.x86_64.rpm"
        "rpm-4.11.3-45.el7.x86_64.rpm"
        "rpm-build-4.11.3-45.el7.x86_64.rpm"
        "rpm-build-libs-4.11.3-45.el7.x86_64.rpm"
        "rpm-libs-4.11.3-45.el7.x86_64.rpm"
        "rpm-python-4.11.3-45.el7.x86_64.rpm"
        "rpm-sign-4.11.3-45.el7.x86_64.rpm"
        "sqlite-3.7.17-8.el7_7.1.x86_64.rpm"
        "tcl-8.5.13-8.el7.x86_64.rpm"
        "tcl-devel-8.5.13-8.el7.x86_64.rpm"
        "tk-8.5.13-6.el7.x86_64.rpm"
        "tix-8.4.3-12.el7.x86_64.rpm"
        "tix-devel-8.4.3-12.el7.x86_64.rpm"
        "tkinter-2.7.5-89.el7.x86_64.rpm"
        "yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm"
        "yum-metadata-parser-1.1.4-10.el7.x86_64.rpm"
        "yum-3.4.3-168.el7.centos.noarch.rpm"
    )
    function get_needed_packs() {
        rpm -q yum
        rpm -qR yum-3.4.3-168.el7.centos.noarch
    }
    function reinstall_yum() {
        cd /install
        mkdir temp
        for pack in ${packages[@]}; do
            if [[ ! -e temp/$pack ]]; then
                sudo wget http://mirror.centos.org/centos/7/os/x86_64/Packages/$pack -P temp/
            fi
        done
        sudo rpm -Uvh --replacepkgs temp/*.rpm
    }
    reinstall_yum
    sudo rm -rf temp/*.rpm
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search