Installing Python 2.7 on Centos 6.7 for dns2

https://dmngaya.com/2015/10/25/installing-python-2-7-on-centos-6-7/

https://github.com/h2oai/h2o-2/wiki/installing-python-2.7-on-centos-6.3.-follow-this-sequence-exactly-for-centos-machine-only

 

Installing python 2.7 on centos 6.7:

Follow this sequence exactly for centos machine only
CentOS 6.7 ships with Python 2.6.6 and depends on that specific version. Be careful not to replace it or bad things will happen.
If you need access to a newer version of Python you must compile it yourself and install it side-by-side with the system version.
Here are the steps necessary to install Python 2.7.6. Execute all the commands below as root. Either log in as root temporarily
or use sudo.

To check centos version:

[hduser@base bin]$ cat /etc/redhat-release
CentOS release 6.7 (Final)

Install development tools:

In order to compile Python you must first install the development tools

sudo yum groupinstall "Development tools"

You also need a few extra libs installed before compiling Python
or else you will run into problems later when trying to install various packages:

sudo yum install zlib-devel
sudo yum install bzip2-devel
sudo yum install openssl-devel
sudo yum install ncurses-devel
sudo yum install sqlite-devel

Download, compile and install Python

The –no-check-certificate is optional

cd /opt
sudo wget --no-check-certificate https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
sudo tar xf Python-2.7.6.tar.xz
cd Python-2.7.6
sudo ./configure --prefix=/usr/local
sudo make && sudo make altinstall

It is important to use altinstall instead of install, otherwise you will end up with two different versions of
Python in the filesystem both named python.

(Depending on your version of wget, you may need to add the –no-check-certificate option to the wget command line.)

After running the commands above your newly installed Python 2.7.6 interpreter will be available
as /usr/local/bin/python2.7 and the system version of Python 2.6.6 will be available as /usr/bin/python and /usr/bin/python2.6.

Add that some python libraries (such as Theano) require a dynamic library:

sudo ./configure –enable-shared –prefix=/usr/local   LDFLAGS="-Wl,–rpath=/usr/local/lib"

If you get this error:
onfigure: WARNING: you should use –build, –host, –target
configure: WARNING: invalid host type: –enable-shared
configure: error: invalid variable name: `–prefix’

try this command:

sudo ./configure --enable-shared \
            --prefix=/usr/local \
            LDFLAGS="-R /usr/local/lib"

Check with:

[hduser@base Python-2.7.6]$ ls -ltr /usr/bin/python*
-rwxr-xr-x 2 root root 4864 23 juil. 16:23 /usr/bin/python2.6
-rwxr-xr-x 2 root root 4864 23 juil. 16:23 /usr/bin/python
lrwxrwxrwx 1 root root 6 16 août 17:26 /usr/bin/python2 -> python
[hduser@base Python-2.7.6]$ ls -ltr /usr/local/bin/python*
-rwxr-xr-x 1 root root 6214485 24 oct. 12:18 /usr/local/bin/python2.7
-rwxr-xr-x 1 root root 1674 24 oct. 12:19 /usr/local/bin/python2.7-config

If things don’t look right, you might need to create a symbolic link in /usr/local/bin:

cd /usr/local/bin
ls -ltr python*

WARNING: don’t do this before checking the $PATH for root. if it has /usr/local/bin before /usr/bin, it will see python2.7 first i.e.

root@openstack h2o]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

If you add this link, do a “which python” for the user and for root. If root is pointing to /usr/local/bin/python, remove the link you just added, and figure out something else.

sudo ln -s /usr/local/bin/python2.7 /usr/local/bin/python
[hduser@base bin]$ which python
/usr/local/bin/python
[hduser@base bin]$ python
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
sudo su - hduser
[hduser@base ~]$ python
Python 2.7.6 (default, Oct 24 2015, 12:14:45)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

Installing and configuring distribute (setuptools):

After installing Python 2.7.6 you also need to install distribute (setuptools) so you can easily install new packages in the right location.

sudo wget https://bootstrap.pypa.io/ez_setup.py
sudo /usr/local/bin/python2.7 ez_setup.py
sudo /usr/local/bin/easy_install-2.7 pip

The commands above will generate the script /usr/local/bin/easy_install-2.7.
Use this script to install packages for your new Python version.
You should be able to use “easy_install” if “which easy_install” points to the correct 2.7 versions.

If this method to install the setuptools does not work, you can follow the link:https://github.com/pypa/setuptools.

I’m jumping between two different machine installs here, sorry about that,
pay attention to /usr/local/bin vs /usr/bin.

[hduser@base ~]$ which pip
/usr/local/bin/pip
[hduser@base ~]$ which easy_install
/usr/local/bin/easy_install
[hduser@base ~]$ ls -ltr /usr/local/bin/easy_install*
-rwxr-xr-x 1 root root 334 Oct 24 13:52 /usr/local/bin/easy_install-2.7
-rwxr-xr-x 1 root root 326 Oct 24 13:52 /usr/local/bin/easy_install
sudo /usr/local/bin/easy_install-2.7 requests
sudo /usr/local/bin/easy_install-2.7 psutil
sudo /usr/local/bin/easy_install-2.7 paramiko

I had to rename pip and easy_install in /user/local/bin and create links.
The existing ones were 2.6 variants. Check first though if pip and easy_install act right after install.
On this system they did:

[hduser@base ~]$ cd /usr/local/bin

[hduser@base bin]$ ls -ltr pip*
-rwxr-xr-x 1 root root 296 Oct 24 13:53 pip2.7
-rwxr-xr-x 1 root root 290 Oct 24 13:53 pip
-rwxr-xr-x 1 root root 292 Oct 24 13:53 pip2

I think if root uses pip or easy_install it will install into python 2.7, not 2.6 maybe that doesn’t matter.

On this system, it’s because /usr/local/bin comes before /usr/bin.

[hduser@base bin]$ which pip
/usr/local/bin/pip
[hduser@base bin]$ which easy_install
/usr/local/bin/easy_install

[hduser@base bin]$ pip --version
pip 7.1.2 from /usr/local/lib/python2.7/site-packages/pip-7.1.2-py2.7.egg (python 2.7)
[hduser@base bin]$ easy_install --version
setuptools 18.4 from /usr/local/lib/python2.7/site-packages/setuptools-18.4-py2.7.egg (Python 2.7)
[hduser@base bin]$ pip2.7 --version
pip 7.1.2 from /usr/local/lib/python2.7/site-packages/pip-7.1.2-py2.7.egg (python 2.7)

Fixing the $PATH would make that correct, since the 2.6 gets resolved correctly with /usr/bin.
In any case, if this doesn’t cause a problem due to $PATH in root or users, you can do this:

cd /usr/local/bin
sudo mv pip pip2.6
sudo mv easy_install easy_install-2.6
sudo ln -s pip2.7 pip
sudo ln -s easy_install-2.7 easy_install
result in /usr/local/bin
cd /usr/local/bin
[hduser@base bin]$ ls -ltr /usr/local/bin
total 6128
lrwxrwxrwx 1 root root 21 Aug 26 21:24 erl -> ../lib/erlang/bin/erl
lrwxrwxrwx 1 root root 22 Aug 26 21:24 erlc -> ../lib/erlang/bin/erlc
lrwxrwxrwx 1 root root 22 Aug 26 21:24 epmd -> ../lib/erlang/bin/epmd
lrwxrwxrwx 1 root root 25 Aug 26 21:24 run_erl -> ../lib/erlang/bin/run_erl
lrwxrwxrwx 1 root root 24 Aug 26 21:24 to_erl -> ../lib/erlang/bin/to_erl
lrwxrwxrwx 1 root root 26 Aug 26 21:24 dialyzer -> ../lib/erlang/bin/dialyzer
lrwxrwxrwx 1 root root 23 Aug 26 21:24 typer -> ../lib/erlang/bin/typer
lrwxrwxrwx 1 root root 25 Aug 26 21:24 escript -> ../lib/erlang/bin/escript
lrwxrwxrwx 1 root root 26 Aug 26 21:24 run_test -> ../lib/erlang/bin/run_test
-rwxr-xr-x 1 root root 18547 Oct 24 12:18 smtpd.py
-rwxr-xr-x 1 root root 84 Oct 24 12:18 pydoc
-rwxr-xr-x 1 root root 99 Oct 24 12:18 idle
-rwxr-xr-x 1 root root 101 Oct 24 12:18 2to3
-rwxr-xr-x 1 root root 6214485 Oct 24 12:18 python2.7
-rwxr-xr-x 1 root root 1674 Oct 24 12:19 python2.7-config
lrwxrwxrwx 1 root root 24 Oct 24 12:44 python -> /usr/local/bin/python2.7
-rwxr-xr-x 1 root root 334 Oct 24 13:52 easy_install-2.7
-rwxr-xr-x 1 root root 326 Oct 24 13:52 easy_install-2.6
-rwxr-xr-x 1 root root 296 Oct 24 13:53 pip2.7
-rwxr-xr-x 1 root root 290 Oct 24 13:53 pip2.6
-rwxr-xr-x 1 root root 292 Oct 24 13:53 pip2
lrwxrwxrwx 1 root root 6 Oct 24 14:18 pip -> pip2.7
lrwxrwxrwx 1 root root 16 Oct 24 14:18 easy_install -> easy_install-2.7
cd /usr/bin

sudo ln -s /usr/local/bin/pip2.7 pip
sudo ln -s /usr/local/bin/easy_install-2.7 easy_install
result in /usr/bin

ls -ltr /usr/bin/pip
[hduser@base bin]$ ls -ltr /usr/bin/pip
lrwxrwxrwx 1 root root 21 Oct 24 14:22 /usr/bin/pip -> /usr/local/bin/pip2.7
ls -ltr /usr/bin/easy_install
[hduser@base bin]$ ls -ltr /usr/bin/easy_install
lrwxrwxrwx 1 root root 31 Oct 24 14:23 /usr/bin/easy_install -> /usr/local/bin/easy_install-2.7
Tags