1. Description of the problem
According to the Python version, Python is currently divided into two main categories, namely: python2.x and Python 3.x. Among them, python2.x is widely used in various projects, and has been supported by many communities, and python3.x as the latest version, gradually become the future development trend of Python language, began to be applied to various projects. As you can see, in order to meet the requirements of the Python version of development projects, you need to configure a separate running environment in the current operating system environment, which is based on Python's virtualenv tools to meet the requirements. In addition, by configuring a standalone Python environment, you can avoid problems where some scripts in your system will not function correctly by installing another Python version directly.
2. Specific tasks
Operating system version number: CentOS Linux release 7.2.1511
Main Use tool: Virtualenv
Target python version number: Python 2.7.5 and Python 3.4.3
3. Process description
3.1 Installation Python3.4.3
Because the operating system has its own Python2.7.5 (Python 2.x) language version, you only need to install and configure the Python3.4.3 (Python 3.x) language version.
The Python3.4.3 installation and configuration script looks like this:
wget https://www.python.org/ftp/python/3.4.3/Python-3.4.3.tgz
tar-xzvf python-3.4.3.tgz
cd Python-3.4.3
./configure--prefix=/usr/local--with-ensurepip=install
make
sudo make Altinstall
Running the above command at the Linux terminal, you can find the python3.4 language version of the completed compilation in the specified directory/usr/local/bin/, and you can find that the system Python default interpreter version has not changed by comparing the Python--version.
Note The main points:
1 the "./configure" line command is used to generate the makefile file for the next stage of the compilation step, where the "--prefix" option specifies the software installation directory, which, for example, is known to specify the Software installation directory as "/usr/local", The related execution files are installed in the bin directory under them, namely:/usr/local/bin, the resource files are installed in the share directory under them, namely:/usr/local/share; "--with-ensurepip" option is used to ensure that the PIP tool is properly installed, which is the recommended option.
2 the "sudo make altinstall" line command is used to install software code that has been compiled and is generally required to be executed as root. The reason for using "make Altinstall" instead of "make install" is to skip the steps of creating Python-related soft links in makefile files, avoiding "make install" The direct build link overwrites the original Python version, causing the system script to not function properly.
3 The system may complain when the script executes to the sudo make Altinstall command. For example, the "Python installation Error:pip 6.0.8 requires SSL/TLS" error occurred during software installation because the Python PIP tool requires SSL packets to be installed, and the solution is to install using the Yum Package management tool Openssl-devel "package, whose execution command is shown below.
sudo yum install Openssl-devel
3.2 Installation Virtualenv
3.2.1 Configuration Pip Tool
1) Install PIP tool
Wget-q http://peak.telecommunity.com/dist/ez_setup.py
python ez_setup.py
sudo easy_install pip
2) Update the PIP tool
sudo pip install--upgrade pip
3.2.2 Configuration Virtualenv Tool
1 Install Virtualenv Tool
sudo pip install virtualenv
2) Update Virtualenv tool
sudo pip install--upgrade virtualenv
3.3 Configuring the Python standalone Environment
3.3.1 Configuration python3.x Environment
1 Create a virtual environment
According to the above Python3.4 installation directory, specify the Python interpreter version, create a "py34env" directory in the current user's home directory, and use that name for the associated environment.
sudo virtualenv-p/usr/local/bin/python3.4 py34env
2 Activate the virtual environment
You can activate the virtual environment by running the command shown below, with the end shell prompt adding the word "(py34env)", which allows users to configure various projects in the environment.
SOURCE Py34env/bin/activate
3 Exit the virtual environment
Deactivate
3.3.1 Configuration python2.x Environment
1 Create a virtual environment
According to the above Python2.7 installation directory, specify the Python interpreter version, create a "py27env" directory in the current user's home directory, and use that name for the associated environment.
sudo virtualenv-p/usr/local/bin/python2.7 py27env
2 Activate the virtual environment
You can activate the virtual environment by running the command shown below, with the end shell prompt adding the word "(py34env)", which allows users to configure various projects in the environment.
SOURCE Py27env/bin/activate
3 Exit the virtual environment
Deactivate
4. Summary of issues
Based on the actual environment and previous experience, the Virtualenv tool was successfully used to configure the Python project environment in Linux environment.
If there is any mistake, I would like you to point out.
github:https://github.com/o7878x
E-mail:dongcai.mo@gmail.com