Python installation process in Linux environment (including Setuptools)

Source: Internet
Author: User
Tags install django

I do not want to use the Apt-get install method such as Ubuntu for Python installation, but in Linux under the way of using the source package Python installation.

First, download the Python source package

Open the shell terminal under Ubuntu and download the Python source package via the wget command, as shown in:

Download the python-2.7.3.tgz to the/OPT directory.

Second, the extraction of Python

Third, the compilation and installation of Python

It must be configured before it is compiled for Python. During the installation process on the Unix/linux platform, the configuration and compilation process has all been automated, and all we need to do is to enter a few commands and return.

By executing the script./configure starts compiling, which can determine the configuration of the system and create the corresponding makefile file. You can also pass some parameter options to configure this script. When this step is complete, you can run make. The operation is as follows:

By adding--prefix to specify the installation path for Python at/usr/local/python2.7, after the configuration is complete, we can perform the make operation.

The above make compile time may be relatively long, about 5-6 minutes, after completion we can arrange the operation, enter the command made install (note permission), as follows:

Let's take a look at the installed Python directory with the following instructions:

The above adds the Python installation directory to the./configure, so we use the LS command to view this directory's information. Where the bin directory is used to store Python's related execution program.

However, since this is our own manual python installed in the/usr/local/python2.7 directory, the $PATH environment variable cannot find the Python interpreter under this directory, you can add a soft link, the code is as follows:

With the Ln-s/usr/local/python2.7/bin/python/bin/python2.7 command, you can create a soft link file under the/bin path python2.7, and when you access this link file, you can indirectly access/usr/local/ The Python program under the python2.7. This works like a shortcut under Windows.

The following can be done by running the Python command interaction mode to view the version of Python that was just installed:

As shown above, the Python interpreter under/usr/local/python2.7 can be accessed by direct execution of python2.7, which is the Python 2.7.3, which is the version of Python we just downloaded, or can be ordered by:

Python2.7-v to view. This completes the Python installation.

Four, the installation process of Setuptools

1, Setuptools download

Setuptools source download Similar to Python, Google on the first search is, through the wget command to download, instructions are as follows:

2, Setuptools the decompression

3. Compilation and installation of Setuptools

Compile the following, using the python2.7 version of the program to execute the setup.py script, which takes the parameter build and executes the compilation process.

(Note: If a different version of the Python interpreter is executed, such as python2.6, the Setuptools will be installed in the appropriate version directory)

If the compilation is OK, it can be installed, similar to the above instruction, as follows:

If you do not have a problem, the installation is successful, but the current installation is not successful, the following error is displayed:

According to the error, the main error is "Compression requires the (missing) zlib module", the error is due to the lack of zlib modules, But the most fundamental reason is that there is no dependency check before installing python2.7.3, and it is best to check with the command sudo apt-get build-dep python. To resolve the missing zlib module issue, you must install the Zlib1g-dev package before installing python2.7.3, reinstall python2.7.3 after installation, and then run sudo python2.7 setup.py Install to solve the problem normally, as follows:

Appears to indicate that the Setuptools tool has been installed successfully. And you can see the path of this setuptools installation under the/usr/local/python/python2.7 directory.

We can take a look at:

We can see that there are some easy_install programs in the Python directory just installed, these are some of the programs of the Setuptools tool, which makes it easy for us to install third-party modules later, here we continue to make a soft link:

This way, when we enter Easy_install directly, we can access the program.

4. Automatic installation of Django and NumPy with Setuptools

Install the Django command as follows:

sudo easy_install Django

But sometimes "Unknow url Type:htpps" error occurs, such as (I happened, very unfortunate!)

There is only one workaround for the above problem, that is, the Libssl-dev library is not installed prior to installing python2.7.3, so you need to install this library, and then install the Python and setuptools again as described above, and then use Easy_ Install Django to install successfully at this time. Install the Libssl-dev Library command as follows:

sudo apt-get install Libssl-dev

Install the NumPy command as follows:

sudo easy_install numpy

Can be installed automatically, this way and sudo apt-get install similar

Python installation process in Linux environment (including Setuptools)

Related Article

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.