Trang chủ > Lập trình, Linux > How to install Python 2.7 and 3.3 on CentOS 6

How to install Python 2.7 and 3.3 on CentOS 6


CentOS 6.2 and 6.3 ships with Python 2.6.6. You can manually install Python 2.7 and Python 3.3 but you must be careful to leave the system version alone. Several critical utilities, for example yum, depend on Python 2.6.6 and if you replace it bad things will happen.

Below are the steps necessary to install Python 2.7.3 and Python 3.3.0 without touching the system version of Python. The procedure is exactly the same for both versions except for the filenames. People have reported that this also works for CentOS 5.8 but I haven’t tested that. Execute all the commands below as root either by logging in as root or by using sudo.

Install development tools

In order to compile Python you must first install the development tools and a few extra libs. The extra libs are not strictly needed to compile Python but without them your new Python interpreter will be quite useless.

# yum groupinstall "Development tools"
# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel

Download and install Python

It is critical that you use make altinstall below. If you use make install you will end up with two different versions of Python in the filesystem both named python. This can lead to problems that are very hard to diagnose.

Download and install Python 2.7.3

# wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
# tar xf Python-2.7.3.tar.bz2
# cd Python-2.7.3
# ./configure --prefix=/usr/local
# make && make altinstall

Download and install Python 3.3.0

# wget http://python.org/ftp/python/3.3.0/Python-3.3.0.tar.bz2
# tar xf Python-3.3.0.tar.bz2
# cd Python-3.3.0
# ./configure --prefix=/usr/local
# make && make altinstall

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

Download and install Distribute

Distribute provides a framework for installing packages from the Python Package Index. Each Python interpreter on your system needs its own install of Distribute.

You can find out what the latest version of Distribute is here. At the time of this edit the current version is 0.6.35. Replace the version number below if there is a newer version available.

Download and install Distribute for Python 2.7

# wget http://pypi.python.org/packages/source/d/distribute/distribute-0.6.35.tar.gz
# tar xf distribute-0.6.35.tar.gz
# cd distribute-0.6.35
# python2.7 setup.py install

This generates the script /usr/local/bin/easy_install-2.7 that you use to install packages for Python 2.7. It puts your packages in /usr/local/lib/python2.7/site-packages/.

Download and install Distribute for Python 3.3

# wget http://pypi.python.org/packages/source/d/distribute/distribute-0.6.35.tar.gz
# tar xf distribute-0.6.35.tar.gz
# cd distribute-0.6.35
# python3.3 setup.py install

This generates the script /usr/local/bin/easy_install-3.3 that you use to install packages for Python 3.3. It puts your packages in /usr/local/lib/python3.3/site-packages/.

What’s next?

Working with multiple versions of Python is difficult and error-prone. I strongly recommend that you install virtualenv and learn how to use it. Virtualenv is a Virtual Python Environment builder that makes it possible to run Python in a sandbox-like environment. Each sandbox can have its own Python version and packages. This is very useful when you work on multiple projects, each with its own dependencies.

Install and use virtualenv for Python 2.7

# easy_install-2.7 virtualenv
# virtualenv-2.7 --distribute someproject
New python executable in someproject/bin/python2.7
Also creating executable in someproject/bin/python
Installing distribute...................done.
Installing pip................done.
# source someproject/bin/activate
(someproject)# python --version
Python 2.7.3
(someproject)#

Install and use virtualenv for Python 3.3

# easy_install-3.3 virtualenv
# virtualenv-3.3 --distribute otherproject
New python executable in otherproject/bin/python3.3
Also creating executable in otherproject/bin/python
Installing distribute...................done.
Installing pip................done.
# source otherproject/bin/activate
(otherproject)# python --version
Python 3.3.0
(otherproject)#

Link: http://toomuchdata.com/2012/06/25/how-to-install-python-2-7-3-on-centos-6-2/
  1. 27/07/2013 lúc 8:22 sáng

    Hi to all, the contents existing at this website are actually awesome for
    people experience, well, keep up the good work fellows.

  2. 05/08/2013 lúc 5:38 chiều

    Attractive section of content. I just stumbled
    upon your blog and in accession capital to assert that I get in fact enjoyed account your blog posts.
    Anyway I will be subscribing to your feeds and even I achievement you access
    consistently quickly.

  1. 22/07/2013 lúc 8:38 chiều

Gửi phản hồi

Mời bạn điền thông tin vào ô dưới đây hoặc kích vào một biểu tượng để đăng nhập:

WordPress.com Logo

Bạn đang bình luận bằng tài khoản WordPress.com Log Out / Thay đổi )

Twitter picture

Bạn đang bình luận bằng tài khoản Twitter Log Out / Thay đổi )

Facebook photo

Bạn đang bình luận bằng tài khoản Facebook Log Out / Thay đổi )

Google+ photo

Bạn đang bình luận bằng tài khoản Google+ Log Out / Thay đổi )

Connecting to %s

%d bloggers like this: