Here I don't want to install Python using apt-Get install in Ubuntu, but install Python using the source code package in Linux.
1. Download The Python source code package
Open the shell terminal in Ubuntu and use the wget command to download the Python source code package, as shown in:
Download python-2.7.3.tgz to the/OPT directory.
Ii. Decompress Python
Iii. Python compilation and Installation
You must configure Python before compiling it. During installation on Unix/Linux, the configuration and compilation processes are all automated. All we need to do is enter several commands and press Enter.
Execute the script./configure to start compilation. This process can determine the system configuration and create the corresponding MAKEFILE file. You can also pass some Parameter options to configure this script. After this step is completed, you can run make. The operation is shown in:
Add -- prefix to specify the installation path of python in/usr/local/python2.7. After the configuration is complete, we can execute the make operation.
The above make compilation may take a long time, about 5-6 minutes. After completing the compilation, we can arrange the operation. Enter the command make install (pay attention to permissions) as follows:
Next, let's check the python directory after installation. The command is as follows:
The Python installation directory is added during./configure, so we use the LS command to view the information of this directory. The bin directory is used to store Python-related execution programs.
However, because we manually install python in the/usr/local/python2.7 directory, the python interpreter in this directory cannot be found in the $ PATH environment variable, to do this, you can add a soft link. The Code is as follows:
You can use the Ln-S/usr/local/python2.7/bin/Python/bin/python2.7 command to create a soft link file python2.7 in the/bin path. When you access this link file, you can indirectly access the python program under/usr/local/python2.7. This is similar to the shortcut in windows.
You can run the python command interaction mode to view the Python version you just installed:
As shown above, you can directly execute python2.7 to access the python interpreter under/usr/local/python2.7. Its version is Python 2.7.3, which is the Python version we just downloaded, you can also run the following command:
Python2.7-v. Now Python installation is complete.
Iv. Installation Process of setuptools
1. Download setuptools
The download of setuptools source code is similar to that of Python. The first search on Google is to download the code using the wget command. The command is as follows:
2. Decompress setuptools
3. setuptools compilation and Installation
Compile the following code. Run the setup. py script using a python 2.7 program. This script includes the parameter build and runs the compilation process.
(Note: If you use another version of Python interpreter for execution, such as python2.6, you will install setuptools to the corresponding version directory)
If the compilation is OK, you can install it, which is similar to the preceding Command, as follows:
If no problem occurs, the installation is successful. However, if the installation fails, the following error is displayed:
According to the error message, the main error is "compression requires the (missing) zlib module". The error is due to the lack of zlib module, but the most fundamental cause is that no dependency check is performed before python2.7.3 is installed, run the sudo apt-Get build-dep Python command to perform the check. So to solve the lack of zlib module, you must install the zlib1g-dev package before installing python2.7.3, and then reinstall python2.7.3, and then run sudo python2.7 setup. py
In this case, the problem can be solved normally, as shown below:
If it appears, it indicates that the setuptools tool has been installed successfully. The installation path of setuptools is in the/usr/local/Python/python2.7 directory.
Let's take a look:
We can see that some easy_install programs exist under the just-installed Python directory. These are some programs of the setuptools tool, which will facilitate the use of third-party modules later. Here we will continue to provide a soft link:
In this way, you can access this program by directly entering easy_install.
4. Use setuptools to automatically install Django and numpy
The command to install Django is as follows:
Sudo easy_install Django
However, sometimes the "unknow URL type: htpps" error occurs. For example, (this happens to me, unfortunately !)
There is only one solution to the above problem, that is, the libssl-dev library is not installed before python2.7.3 is installed. Therefore, you need to install this library and then install Python and setuptools again as described above, and then install Django with easy_install. Run the following command to install the libssl-dev Library:
Sudo apt-Get install libssl-Dev
Run the following command to install numpy:
Sudo easy_install numpy
This method is similar to sudo apt-Get install.