I am working on a RHEL system. I have two versions of Python installed on my system: Python 2.4 and Python 2.7, but I have created an alias in the .bashrc file so that the python command prompts Python 2.7 instead of Python 2.4.
I need to install zlib in my system. I tried to install it using the yum command:
yum install zlib
yum install zlib-devel
both worked fine, but when I type “python”, I still cannot see zlib installed:
[root@mymachine]# python
Python 2.7 (r27:82500, Jan 18 2012, 17:03:29)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import zlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named zlib
But if I import zlib from Python 2.4, it works! Why? I need zlib to be installed using Python 2.7. How can I do that? Thank you in advance!
Generally you will only find RPMs for the default Python version in the yum repository, however that shouldn’t really be applicable here since zlib should be installed by default in your Python 2.7 installation.
Check
sys.pathusingimport sys; print sys.pathand make sure that you have the lib directories for your Python 2.7 installation, it is possible that whatever you are doing in .bashrc is causing you to pick up the Python 2.4 environment.Here is the location of my
zlibmodule, which may be useful in trying to track down the location of yours so you can make sure it is onsys.path.If you cannot find it then you should reinstall Python 2.7.