Since there is currently CentOS 7 is dependent on python2 some packets, such as on yum, so Python3 during installation, to avoid modification of the system Python2 settings.
Install software dependencies and build environment
When installing Python3, use the source code compiler installation, before installation to ensure that relevant development kit set and the corresponding dependencies already installed, if not installed dependencies, may cause some problems after the installation is complete, such as interactive environment, buttons appear problem because of the lack readline dependence.
1 |
yum groupinstall Development Tools |
Source obtain Python3
In Python official website to download the source code ( https://www.python.org/downloads/release/python-364/ ) and unzip
1 |
wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz |
Compile and install Python3
After the files are decompressed python source code directory, compiled Configuration option to compile and install
1 |
mkdir /usr/local/python3 |
Softlinks Python3 and the pip3
1 |
ln -s /usr/local/python3/bin/python3 /usr/bin/python3 |
In addition to the soft connection is established pip3 the simultaneous presence within the local system python2 and version 3, use pip (or other similar script command script file in the folder) command, python interpreter version it is associated may not be expected the version number. Therefore, you can directly use the first command in the directory are located in the two pip, pip and see what exactly is unavailable. In addition, you can specify a version number python interpreter directly, provided that you have python2,3 make a distinction, use the following command to install similarpython3 -m pip install packagename
Virtualenv installed in Python2 environment
Need to be installed before installing virtualenv pip (2), pip and upgrade installation method in https://pip.pypa.io/en/stable/installing/ are described in detail, following installation pip, pip installation using virtualenv:
1 |
pip install virtualenv |
Create or specify a directory (or subdirectory) for deploying a virtual environment virtualenv, where virtual environments python3
1 |
mkdir Development/myproject |
Activate the virtual environment: in virtualenv directorysource venv/bin/activate
Exit the virtual environment:deactivate
Original: Big Box CentOS7 compile and install Python3 and Python2 coexistence - Manson memo