Tuesday, 19 June 2018

Step by Step how to upgrade Python 2.6.x to 2.7.x with Kafka module.

Step1:-

[root@sankar-devops]# python --version
Python 2.6.6

[root@sankar-devops]# python 
Python 2.6.6 (r266:84292, Aug 18 2016, 08:36:59) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.


Step2:
[root@sankar-devops]#cd /opt

[root@sankar-devops opt]#wget http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz  

[root@sankar-devops opt]#xz -d Python-2.7.8.tar.xz  

[root@sankar-devops opt]#tar -xvf Python-2.7.8.tar 

Step3: [root@sankar-devops opt]# cd Python-2.7.8
[root@sankar-devops Python-2.7.8]# ./configure --prefix=/usr/local
....
....
....
checking for %zd printf() format support... yes
checking for socklen_t... yes
checking for build directories... done
configure: creating ./config.status
config.status: creating Makefile.pre
config.status: creating Modules/Setup.config
config.status: creating Misc/python.pc
config.status: creating Modules/ld_so_aix
config.status: creating pyconfig.h
creating Modules/Setup
creating Modules/Setup.local
creating Makefile


[root@sankar-devops Python-2.7.8]# make

[root@sankar-devops Python-2.7.8]# make altinstall
running install_scripts
copying build/scripts-2.7/pydoc -> /usr/local/bin
copying build/scripts-2.7/smtpd.py -> /usr/local/bin
copying build/scripts-2.7/idle -> /usr/local/bin
copying build/scripts-2.7/2to3 -> /usr/local/bin
changing mode of /usr/local/bin/pydoc to 755
changing mode of /usr/local/bin/smtpd.py to 755
changing mode of /usr/local/bin/idle to 755
changing mode of /usr/local/bin/2to3 to 755
running install_egg_info
Writing /usr/local/lib/python2.7/lib-dynload/Python-2.7.8-py2.7.egg-info
rm /usr/local/lib/python2.7/lib-dynload/_sysconfigdata.py*

Step4:
Put the below line in ~/.bashrc file:

[root@sankar-devops]#vim ~/.bashrc
....
....
alias python=/usr/local/bin/python2.7

:wq!

Now execute the command:

[root@sankar-devops]#source ~/.bashrc


Step5:
Kafka Module installation on Python 2.7.x

[root@sankar-devops]#cd /usr/local/lib/python2.7/site-packages


[root@sankar-devops]#cd /usr/lib/python2.6/

[root@sankar-devops]#cp -r kafka /usr/local/lib/python2.7/site-packages/

[root@sankar-devops]#cp -r kafka_python-1.4.4.dev-py2.6.egg-info/  /usr/local/lib/python2.7/site-packages/

[root@sankar-devops]#cp -r pip*  /usr/local/lib/python2.7/site-packages/

  
Step6: Verification
[root@sankar-devops]# python
Python 2.7.8 (default, Jun 18 2018, 11:10:21) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> help()

Welcome to Python 2.7!  This is the online help utility.


help> modules

Please wait a moment while I gather a list of all available modules...

BaseHTTPServer      ast                 imp                 shelve
Bastion             asynchat            importlib           shlex
Cookie              base64              json                smtplib
DLFCN               bdb                 kafka               sndhdr
Dialog              binascii            keyword             socket
DocXMLRPCServer     binhex              lib2to3             spwd
FileDialog          bisect              linecache           sqlite3


help> modules kafka

Here is a list of matching modules.  Enter any module name to get more help.

kafka 
kafka.client 
kafka.client_async 
kafka.cluster 
kafka.codec 
kafka.common 
kafka.conn 
kafka.consumer 
kafka.consumer.base 
kafka.consumer.fetcher