0

I have to installed Python 2.7 in centos as I was facing some issues managing different versions of python. But I have messed up the yum settings and not able to use it.

Steps I took to install Python

cd /usr/src
wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
tar xzf Python-2.7.18.tgz
cd Python-2.7.18
./configure --enable-optimizations
make install
python -V

Output

Python 2.7.18

When I type 'yum' I receive following message.

There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

   No module named yum

Please install a package which provides this module, or
verify that the module is installed correctly.

It's possible that the above module doesn't match the
current version of Python, which is:
2.7.18 (default, Dec  7 2020, 22:27:41) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]

If you cannot solve this problem yourself, please go to 
the yum faq at:
  http://yum.baseurl.org/wiki/Faq

I have referred to similar questions like this, and I will add the response here.

find / -type f -executable -name 'python2*'

/usr/local/bin/python2.7-config
/usr/local/bin/python2.7

find / -type f -executable -name 'python3*'

/usr/bin/python3.4m
/usr/bin/python3.6m-config
/usr/bin/python3.4
/usr/bin/python3.6
/usr/bin/python3.6m
/usr/bin/python3.6m-x86_64-config

Running /usr/local/bin/python2.7 (this raises a import error)

Python 2.7.18 (default, Dec  7 2020, 22:27:41) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import yum
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named yum

cat which yum | head -1

#!/usr/bin/python

then as root, I run the following to create a symbolic link

ln -s /usr/local/bin/python2.7 /usr/bin/python 

But I am still facing the same issue while running yum command.

Adding more info on yum, rpm -q yum

yum-3.4.3-168.el7.centos.noarch

Verify if yum is installed or not, rpm -V yum-3.4.3-168.el7.centos.noarch.rpm

package yum-3.4.3-168.el7.centos.noarch.rpm is not installed

Then I downloaded this binary package http://mirror.centos.org/altarch/7/os/aarch64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm from here, and installing it with

rpm -ivh yum-3.4.3-168.el7.centos.noarch.rpm

but it says that yum is installed

Preparing...                          ################################# [100%]
    package yum-3.4.3-168.el7.centos.noarch is already installed

checking yum file, cat /usr/bin/yum

#!/usr/bin/python
import sys
try:
    import yum
except ImportError:
    print >> sys.stderr, """\

Update:

output of ls -l /usr/bin/python

lrwxrwxrwx 1 root root 24 Dec  8 09:41 /usr/bin/python -> /usr/local/bin/python2.7
2
  • Please do not cross post: stackoverflow.com/questions/65193144/… – Stephen Rauch Dec 10 '20 at 19:46
  • @StephenRauch I posted it here as I came to know that stackoverflow is limited to programming related questions. Should I delete the question from stackoverflow?? – joel Dec 10 '20 at 19:49
1

You have done everything as worst as possible.

First, you are running a Community Enterprise OS - the last thing you should do, is ./configure and make. Things are managed through package manager only, or you are asking for big trouble.

Second, the operation of trying to install Python 2.7 makes no sense, as this is the default Python version in CentOS 7. As you have guessed by now, many programs depend on it, and that's why when you install/overwritten it through manual compilation, yum was broken - because your "custom" Python 2.7 installation is missing Python modules required for it to run.

Luckily, custom compiled programs by default use prefix /usr/local/ and install in that directory tree.

I would recommend, after thorough investigation, nuking the entire /usr/local/bin/* as it has the custom programs you have compiled. Then recreate the proper link to python program.

rm -rf /usr/local/bin/*
ln -fs /usr/bin/python2 /usr/bin/python

Log out from the system, then log in again. yum should be functional.

No more playing with compilation tools, use packages. In other words, only use yum to install, delete, upgrade programs on your system. Even if you find a case where you miss a program to be packaged (highly unlikely, use pkgs.org search to be sure), it is best to learn packaging and build packages on a separate system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.