• Call us: 1(704) - 858 - 0065
  • Email us: dmngaya@dmnbigdata.com
  • Working Hours: 8am - 6pm

Installing Python 2.7 on Centos 6.7

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:

[php]cat /etc/redhat-release[/php]

CentOS release 6.7 (Final)

Install development tools:

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

[php]sudo yum groupinstall "Development tools"[/php]

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:

[php]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
[/php]

Download, compile and install Python

The –no-check-certificate is optional

[php]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  install; sudo make altinstall
[/php]

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:

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

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:

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

Check with:

[php]ls -ltr /usr/bin/python*[/php]

-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

[php]ls -ltr /usr/local/bin/python*[/php]

-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:

[php]cd /usr/local/bin
ls -ltr python*[/php]

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.

[php]echo $PATH[/php]

/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.

[php]sudo ln -s /usr/local/bin/python2.7 /usr/local/bin/python
which python
python
sudo su - hduser
python
[/php]

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.

[php]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[/php]

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.

[php]which pip
which easy_install
ls -ltr /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
[/php]

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:

[php]cd /usr/local/bin
ls -ltr pip*
[/php]

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.

[php]which pip
which easy_install
pip --version
easy_install --version
pip2.7 --version
[/php]

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:

[php]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
cd /usr/local/bin
ls -ltr /usr/local/bin
[/php]
[php]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
[/php]
[php]cd /usr/bin
sudo ln -s /usr/local/bin/pip2.7 pip
sudo ln -s /usr/local/bin/easy_install-2.7 easy_install
ls -ltr /usr/bin/pip
ls -ltr /usr/bin/easy_install
ls -ltr /usr/bin/easy_install
[/php]

Leave a Reply

Close Menu
×
×

Cart