CentOS6 compile and install the Python2.7.6 method

Source: Internet
Author: User
Tags deprecated

About the method of compiling and installing Python2.7.6 under CentOS6 is very much, the small series has also introduced the related article, the following a tutorial small series to introduce for you, I hope the article can help you.

Under CentOS When upgrading to 2.7.6, there is no installation package installed directly, only the source code compiled to install Python version 2.7.6. This is a process record for compiling and installing Python2.7.6.

Development tools is installed in the CentOS system. To compile and install Python, execute the following code:

The code is as follows Copy Code
$ pushd/usr/local/src
$ sudo mkdir python
$ sudo chown $USER python
$ cd Python
$ wget https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
$ tar zxvf python-2.7.6.tgz
$ CD Python-2.7.6
$./configure--prefix=/usr/local/python-2.7.6 &&
Make
$ sudo make install

Code procedures:

1. Create the Python folder in/usr/local/src and set the Python folder owner to the current user (not root)

2. Go to the created Python directory and download the python2.7.6 source code package from the official website.

3. (non-mandatory) if you want to verify the consistency of the package, you can download the sig file on the official website, and through the PGP check file, you can also verify the downloaded compressed package by the MD5 available on the website. For more information on verification, refer to the integrity of the check file under Linux (MD5,SHA1,PGP). This code ignores this procedure.

4. Unzip the tarball into the current directory and enter the Python-2.7.6 directory

5. Configure Python and compile. This step only uses the--prefix parameter to indicate the installation path.

6. Install Python

The above is a rough process in the case of a successful Python compilation installation, but when I compile it, Python has the following message:

The code is as follows Copy Code

Python build finished, but the necessary bits-to-build these modules were not found:
_BSDDB _sqlite3 _ssl
_tkinter bsddb185 bz2
DBM GDBM ReadLine
Sunaudiodev
To find the necessary bits, look in setup.py in Detect_modules () for the module ' s name.

Of course, each machine because of different configuration, compile error message will be different, such as online someone's error is the following:

The code is as follows Copy Code
Python build finished, but the necessary bits-to-build these modules were not found:
_BSDDB _curses _curses_panel
_sqlite3 _ssl _tkinter
bsddb185 bz2 dbm
DL GDBM Imageop
ReadLine Sunaudiodev zlib
To find the necessary bits, look in setup.py in Detect_modules () for the module ' s name.

Regardless of the error message, meaning is very clear, we compile, the system does not have the means to find the corresponding module information, in order to resolve these errors, we need to install the dependency package in advance, these dependencies are listed as follows (not necessarily complete):

Module Depend on Description
_bsddb Bsddb Interface to Berkeley DB Library. Interface to the Berkeley database
_curses Ncurses Terminal handling for Character-cell displays.
_curses_panel Ncurses A panel stack extension for curses.
_sqlite3 Sqlite DB-API 2.0 interface for SQLite databases. Sqllite,centos can be installed Sqlite-devel
_ssl openssl-devel.i686 Tls/ssl wrapper for socket objects.
_tkinter N/A A thin object-oriented layer on top of TCL/TK. If you do not use a desktop program, you can ignore Tkinter
bsddb185 Old BSDDB Module Old BSDDB module, can be ignored.
bz2 bzip2-devel.i686 Compression compatible with bzip2. Bzip2-devel
Dbm Bsddb Simple "Database" interface.
Dl N/A Call C functions in shared objects. Python2.6 started, has been deprecated.
gdbm gdbm-devel.i686 GNU ' s reinterpretation of dbm
Imageop N/A Manipulate RAW image data. has been deprecated.
ReadLine Readline-devel GNU ReadLine Interface
Sunaudiodev N/A Access to Sun audio hardware. This is for Sun platform, can be ignored under CentOS
Zlib Zlib Compression compatible with gzip


After the compilation is complete, you can then install Python to the specified directory in the sixth step above. After the installation is complete, we can see if Python is installed properly under the installation directory.

The code is as follows Copy Code
$ pushd/usr/local/python-2.7.6/bin
$ python--version
$ sudo mv/usr/bin/python/usr/bin/python.old
$ sudo ln-s Python/usr/bin/python
$ popd
$ python-v
$ sudo sed-i "s/#\!\/usr\/bin\/python/#\!\/usr\/bin\/python.old/"/usr/bin/yum

1. We go to the bin directory under the installation path and view the installed version (version 2.7.6)

2. Rename the existing Python version to backup

3. Create a new version of Python to replace the original python in the/usr/bin directory

4. Test the System Python version (should be the new 2.7.6)

5. If Yum does not work properly, you can simply replace the Python reference with the original Python path via sed.

At this point, complete the Python update compilation installation. If you want to complete the automatic installation, you can save the previous code as a shell script file-it is important to note that you may need to add the installation scripts for each module, which is installed through Yum. You can also refer to the article in 2, which contains the script files that are automatically installed.

CentOS6 compile and install the Python2.7.6 method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.