Sunday, December 11, 2016

Python3 - Compile, install and configure python 3 on Centos 7.x

Python3 - Compile and install =>
Prerequisite tasks:
a. Set up your yum repo and make sure you can install packages.
b. Install following packages:
#  yum groupinstall "Development tools"
# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel


Note: You need to have development tools installed otherwise, you will get your compile failed near the end of the line. If you already have LDAP server setup, you will get an warning related to Kerberos, just ignore.




1. Download the source code
# wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz



2. Extract the package
# cd /var/tmp; mkdir python; cd python/
# ls -ltr ../Python-3.5.2.tgz
# tar -xzvf ../Python-3.5.2.tgz






3. Compile and install
# cd Python-3.5.2/
# ./configure --prefix=/usr/local --enable-shared
# make
# make install
# cd /usr/local/
# cd bin
# ls -lh




4. Make python library available so that you can use python3.

# python3
python3: error while loading shared libraries: libpython3.5m.so.1.0: cannot open shared object file: No such file or directory


# ls -l /usr/local/lib/libpython3.5m.so.1.0

# echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf
# ldconfig
# which python3
/usr/local/bin/python3
# export PATH=$PATH:/usr/local/bin
# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin






5. Check the version you install and start interactive console to start using it.
Note: as of now, most of the system defaults to 2.x version.



# python3 --version
Python 3.5.2
# python3
Python 3.5.2 (default, Dec 11 2016, 12:47:09)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>




6. Print hello world !!!
>>> print("Hello, World!!! \n Welcome to Python")
Hello, World!!!
 Welcome to Python




>>> msg="Hello, World!!! \n Welcome to Python"
>>> print(msg)
Hello, World!!!
 Welcome to Python
>>>


No comments:

Post a Comment