15

I have default python 2.7 and i try to install python3.3 and install pip3 and Django.now when i try to install others using yum i got this error.for a example yum update

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.5 (default, Nov 12 2013, 16:18:42) [GCC 4.8.2 20131017 (Red Hat 4.8.2-1)] If you cannot solve this problem yourself, please go to the yum faq at: http://yum.baseurl.org/wiki/Faq

How can i fix this error?

2
  • 2
    You should not change the system python. yum relies on it. If you install a new python, put it in an alternative path. You can then use virtualenv to use the new python seamlessly. May 11, 2014 at 7:20
  • check here: stackoverflow.com/questions/10624511/…
    – mortymacs
    May 11, 2014 at 11:14

2 Answers 2

19

There is probably many python versions on your system and only one of them has the yum library installed. For some reason the python binary called when you run yum on the command line is not the one who has the yum library installed.

Find the list of python 2 binaries available on your system. Run as root:

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

The output will probably look like that:

/usr/bin/python2.6
/usr/bin/python2.7
...

etc...

For each one of these, run

/usr/bin/python2.x

You'll get a python prompt. Run:

>>> import yum

Do this for every python binary until you find one that doesn't raise an ImportError at this step.

Then find out what is the path that yum is using to run python. This is the first line in the yum script. Run

cat `which yum` | head -1

You'll probably get:

#!/usr/bin/python

Now, run as root:

ln -s /usr/bin/python2.x /usr/bin/python 

(replace python2.x with the good python version you found earlier).

4
  • You are right. But I need to use python2.7 instead of python2.6. How to make python2.7 the default python version?
    – Gank
    Dec 28, 2014 at 6:19
  • That's the purpose of the ln -s /usr/bin/python2.x /usr/bin/python command I wrote in my answer. Replace /usr/bin/python2.x with the location of the python2.7 on your system. If it's not /usr/bin/python2.7, run which python2.7 to find out where it is. Dec 28, 2014 at 10:11
  • Of course, do this only if python2.7 is really supposed to be the default python on your system. If python2.6 is the python version officially supported by your distro, you should keep it that way. Just run python2.7 myapp.py when you want to run an app with python2.7. Dec 28, 2014 at 10:28
  • Yes. Then I can't use easy_install or pip any more, everytime I use python2.7 setup.py install
    – Gank
    Dec 28, 2014 at 12:11
2

I have the same problem.

Yum has been written in Python lang.

So when you upgrade your default Python to new version it will make problem for yum. If you get python --version it will tell you 3.3.

For solving this problem , change python command to python2.7.

First check it:

user@host:~$ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 9 Sep 28  2013 /usr/bin/python -> python3.3

Try it:

mv /usr/bin/python /usr/bin/python-origin
ln -s python2.7 /usr/bin/python

Then check it:

user@host:~$ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 9 Sep 28  2013 /usr/bin/python -> python2.7

If you wish to install python3 in CentOS you should install that via source code.

download main source code via python.org website.
extract archive file.
./configure
make
make install
16
  • when i try to run python --version it says Python 2.7.5 May 11, 2014 at 7:33
  • what is first line of less /usr/bin/yum?
    – mortymacs
    May 11, 2014 at 7:42
  • did you tried to install python3 via the main source code?
    – mortymacs
    May 11, 2014 at 7:47
  • just i download python from the python.org May 11, 2014 at 7:49
  • @user3480706 I upgraded my post , check it again.
    – mortymacs
    May 11, 2014 at 7:55

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