The latest release of the python scripting language is Python 3.4.0 However due to backwards incompatibilities with Python 2, it has not been adopted for CentOS / Redhat Linux 5. The primary reason for this, is because release of ‘yum’ (package management) used in EL5 requires Python 2. Because of this, Python cannot be upgraded in place to version 3 without breaking the package manager.
Therefore to use Python 3, it will need to be installed outside of /usr.
bzip2-devel.i386 0:1.0.3-6.el5_5 bzip2-devel.x86_64 0:1.0.3-6.el5_5 expat-devel.i386 0:1.95.8-11.el5_8
expat-devel.x86_64 0:1.95.8-11.el5_8 gdbm-devel.i386 0:1.8.0-28.el5 gdbm-devel.x86_64 0:1.8.0-28.el5
openssl-devel.i386 0:0.9.8e-22.el5_8.4 openssl-devel.x86_64 0:0.9.8e-22.el5_8.4 readline-devel.i386 0:5.1-3.el5
readline-devel.x86_64 0:5.1-3.el5 sqlite-devel.i386 0:3.3.6-6 sqlite-devel.x86_64 0:3.3.6-6
Dependency Installed:
gdbm.i386 0:1.8.0-28.el5 keyutils-libs-devel.x86_64 0:1.2-1.el5 krb5-devel.x86_64 0:1.6.1-70.el5
libselinux-devel.x86_64 0:1.33.4-5.7.el5 libsepol-devel.x86_64 0:1.15.2-3.el5 libtermcap-devel.x86_64 0:2.0.8-46.1
sqlite.i386 0:3.3.6-6
Dependency Updated:
expat.i386 0:1.95.8-11.el5_8 expat.x86_64 0:1.95.8-11.el5_8 gdbm.x86_64 0:1.8.0-28.el5
krb5-libs.i386 0:1.6.1-70.el5 krb5-libs.x86_64 0:1.6.1-70.el5 krb5-workstation.x86_64 0:1.6.1-70.el5
libselinux.i386 0:1.33.4-5.7.el5 libselinux.x86_64 0:1.33.4-5.7.el5 libselinux-python.x86_64 0:1.33.4-5.7.el5
libselinux-utils.x86_64 0:1.33.4-5.7.el5 libsepol.i386 0:1.15.2-3.el5 libsepol.x86_64 0:1.15.2-3.el5
openssl.i686 0:0.9.8e-22.el5_8.4 openssl.x86_64 0:0.9.8e-22.el5_8.4 sqlite.x86_64 0:3.3.6-6
Complete!
Loaded plugins: logchanges, security
Setting up Install Process
Package openssl-devel-0.9.8e-22.el5_8.4.x86_64 already installed and latest version
Package openssl-devel-0.9.8e-22.el5_8.4.i386 already installed and latest version
Package bzip2-devel-1.0.3-6.el5_5.x86_64 already installed and latest version
Package bzip2-devel-1.0.3-6.el5_5.i386 already installed and latest version
Package expat-devel-1.95.8-11.el5_8.x86_64 already installed and latest version
Package expat-devel-1.95.8-11.el5_8.i386 already installed and latest version
Package gdbm-devel-1.8.0-28.el5.x86_64 already installed and latest version
Package gdbm-devel-1.8.0-28.el5.i386 already installed and latest version
Package readline-devel-5.1-3.el5.x86_64 already installed and latest version
Package readline-devel-5.1-3.el5.i386 already installed and latest version
Package sqlite-devel-3.3.6-6.x86_64 already installed and latest version
Package sqlite-devel-3.3.6-6.i386 already installed and latest version
Nothing to do
[root@bhmed-dt-2q ~]#
Therefore to use Python 3, it will need to be installed outside of /usr.
Installing
Below is the list of command (with inline comments) on what is required to compile and install Python 3 from source. The installation will be done into the prefix /opt/python3. This will ensure the installation does not conflict with system software installed into /usr.- - - - - - - - - - - - #1 will install following- - - - - - - - - - - - - - - - - -
Installed:bzip2-devel.i386 0:1.0.3-6.el5_5 bzip2-devel.x86_64 0:1.0.3-6.el5_5 expat-devel.i386 0:1.95.8-11.el5_8
expat-devel.x86_64 0:1.95.8-11.el5_8 gdbm-devel.i386 0:1.8.0-28.el5 gdbm-devel.x86_64 0:1.8.0-28.el5
openssl-devel.i386 0:0.9.8e-22.el5_8.4 openssl-devel.x86_64 0:0.9.8e-22.el5_8.4 readline-devel.i386 0:5.1-3.el5
readline-devel.x86_64 0:5.1-3.el5 sqlite-devel.i386 0:3.3.6-6 sqlite-devel.x86_64 0:3.3.6-6
Dependency Installed:
gdbm.i386 0:1.8.0-28.el5 keyutils-libs-devel.x86_64 0:1.2-1.el5 krb5-devel.x86_64 0:1.6.1-70.el5
libselinux-devel.x86_64 0:1.33.4-5.7.el5 libsepol-devel.x86_64 0:1.15.2-3.el5 libtermcap-devel.x86_64 0:2.0.8-46.1
sqlite.i386 0:3.3.6-6
Dependency Updated:
expat.i386 0:1.95.8-11.el5_8 expat.x86_64 0:1.95.8-11.el5_8 gdbm.x86_64 0:1.8.0-28.el5
krb5-libs.i386 0:1.6.1-70.el5 krb5-libs.x86_64 0:1.6.1-70.el5 krb5-workstation.x86_64 0:1.6.1-70.el5
libselinux.i386 0:1.33.4-5.7.el5 libselinux.x86_64 0:1.33.4-5.7.el5 libselinux-python.x86_64 0:1.33.4-5.7.el5
libselinux-utils.x86_64 0:1.33.4-5.7.el5 libsepol.i386 0:1.15.2-3.el5 libsepol.x86_64 0:1.15.2-3.el5
openssl.i686 0:0.9.8e-22.el5_8.4 openssl.x86_64 0:0.9.8e-22.el5_8.4 sqlite.x86_64 0:3.3.6-6
Complete!
- - - - - - - - - - - - #1 will install above & if these are already installed we will see following- - - - - - - - - - - - - -
[root@bhmed-dt-2q ~]# yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-develLoaded plugins: logchanges, security
Setting up Install Process
Package openssl-devel-0.9.8e-22.el5_8.4.x86_64 already installed and latest version
Package openssl-devel-0.9.8e-22.el5_8.4.i386 already installed and latest version
Package bzip2-devel-1.0.3-6.el5_5.x86_64 already installed and latest version
Package bzip2-devel-1.0.3-6.el5_5.i386 already installed and latest version
Package expat-devel-1.95.8-11.el5_8.x86_64 already installed and latest version
Package expat-devel-1.95.8-11.el5_8.i386 already installed and latest version
Package gdbm-devel-1.8.0-28.el5.x86_64 already installed and latest version
Package gdbm-devel-1.8.0-28.el5.i386 already installed and latest version
Package readline-devel-5.1-3.el5.x86_64 already installed and latest version
Package readline-devel-5.1-3.el5.i386 already installed and latest version
Package sqlite-devel-3.3.6-6.x86_64 already installed and latest version
Package sqlite-devel-3.3.6-6.i386 already installed and latest version
Nothing to do
[root@bhmed-dt-2q ~]#
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Install required build dependencies
- $ yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
- # Fetch and extract source. Please refer to http://www.python.org/download/releases to ensure the latest source is used.
- $ wget
- https://www.python.org/ftp/python/3.4.0/Python-3.4.0.tgz --no-check-certificate
- https://www.python.org/ftp/python/3.4.0/Python-3.4.0.tar.xz --no-check-certificate
- $ tar -xjf Python-3.2.tar.bz2
- $ cd Python-3.2
- # Configure the build with a prefix (install dir) of /opt/python3, compile, and install.
- $ ./configure --prefix=/opt/python3
- $ make
- $ sudo make install
- #Python 3 will now be installed to /opt/python3.
- $ /opt/python3/bin/python3 -V
- Output: Python 3.2
- Ensure your python 3 scripts and applications query the correct interpreter.
- #!/opt/python3/bin/python3 Generally Work here is completed python3 can be accessed using this path.
- Now make sure you set your new PYTHON as in your PATH. try
- $which python: If this return a different version of python may be your system default then you might want to set your new python3.4 path or in the python3.4 directory try ./python that should open your new 3.4 python.
- echo $PATH
- export PATH=/YOUR/PYTHON/3.4_HOMEDIR/PATH:$PATH
- echo $PATH : (this is temporary, you can add to config files to make this export permanent) notice that i am adding it to the front so it gets picked before our system default.
- Now lets install some packages:
- # Create your virtual env: so this installation will not clash with system default python and/or you are not using the wrong python pip
- $ pyvenv-3.4 py3.4env
- # Activate it:
- $ source py3.4env/bin/activate
- # This should be pointing to the right pip in your new python 3.4 Home
- (py3.4env) $ which pip
- # This checks if your env is clean ..this would not return any output
- (py3.4env) $ pip freeze
- (py3.4env) $ pip install numpy
- (py3.4env) $ pip install pytz