Install a new version of the Python on CentOS without overwriting the system's python installation

Install a new version of the Python on CentOS without overwriting the system's python installation
** You have to decide where to install it based on your needs. If you want to run web server later using this copy of the Python, you may not want to install it in your home directory. Most popular place to go is /opt/.
The default Python comes with the CentOS is version 2.4 which can not meet the requirements of some programs. Here is an instruction of installing a separate newer version of the Python on CnetOS.
Prepare the source code
  1. cd
  2. wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
  3. tar –zvxf Python-2.7.2.tgz
  4. cd Python-2.7.2
  5. configure python so it will not overwriting the system’s default python
    ./configure –prefix= /usr/local/opt/python2.7 --with-threads --enable-shared
1)     --enable-shared is required if you are going to install mod_wsgi. Or you have to rebuild the python library.
2)        However, if you choose –enable-shared parameter you may encounter error while you are trying to install pscopg2. The error message is "ld cannot find lpython2.7". Here is a solution to that:
$ cd /usr/lib64
$ sudo ln -s /usr/local/python2.7/lib/libpython2.7.so.1.0 libpython2.7.so.1.0
   $ sudo ln -s libpython2.7.so.1.0  libpython2.7.so

  1. make and install
  $ make
 $ make install
Now you have successfully installed a fully functional copy of the python library. In order to use it you can do some configuration for this version of the python.
  1. add the following line to user’s .bashrc to create an alias, so you do not need reboot to start using the alias
    alias python='/usr/local/opt/python2.7/bin/python'
2.  Make a symbolic link in the /usr/bin folder:
    $ ln –s /usr/local/python2.7/bin/python /usr/bin/python2.7
3. to make a permanent change then you can run the following as root:
     ln -f /usr/local/python2.7/bin/python /usr/local/bin/python
  1. Configure ld to find your shared libs:
a. create file opt-python2.7.conf under /etc/ld.so.conf.d folder
b. add /usr/local/python2.7/lib into the created file
c. run $ sudo /sbin/ldconfig

After the installation of the new versions of the Python you might need to install the setuptools and pip to work with this version of the Python:
1. Install setuptools
a.         cd
b.        wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e
c.        tar -zvxf setuptools-0.6c11.tar.gzll
d.        cd setuptools-0.6c11
e.        python2.7 setup.py build  ###here use the newly installed python to make sure you are installing it for it
f.        python2.7 setup.py install

     2 Install pip

        Follow the same operation process for installing setuptools.  After installing the pip you may want to make a symbolic link for it in the /usr/bin folder
sudo ln –s /usr/local/python2.7/bin/pip /usr/bin/pip2.7









Reference:

1. Thanks http://thebuild.com/blog/2009/10/17/wordpress-to-djangopostgresql-part-3-installing-apache-python-2-6-psycopg2-and-mod_wsgi/ for tips on overcoming the errors while installing the psycopg2 by link thelibraries to /usr/lib64.

2. http://blog.hackedexistence.com/mediatemple-centos-5-5-ve-server-build-django-1-3-python-2-7-mysql-5-5-php-5-3

No comments:

Post a Comment

Datatable static image not found on the server

When you use ```datatables.min.css``` and ```datatables.min.js``` locally, instead of datatables CDN, you may have encountered that ```sort...