CentOS7 compile and install Python3 and Python2 coexistence - Manson memo

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
2
3
4
5
6
7
8
9
10
11
12
yum groupinstall Development Tools
yum -y install zlib zlib-devel
yum -y install bzip2 bzip2-devel
yum -y install ncurses ncurses-devel
yum -y install readline readline-devel
yum -y install openssl openssl-devel
yum -y install openssl-static
yum -y install xz lzma xz-devel
yum -y install sqlite sqlite-devel
yum -y install gdbm gdbm-devel
yum -y install tk tk-devel
yum -y install db4-devel libpcap-devel

Source obtain Python3

In Python official website to download the source code ( https://www.python.org/downloads/release/python-364/ ) and unzip

1
2
wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
tar -xzvf 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
2
3
4
mkdir /usr/local/python3
cd Python-3.6.4
./configure --prefix=/usr/local/python3
make && make install

Softlinks Python3 and the pip3

1
2
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

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
2
3
mkdir Development/myproject
cd Development/myproject
virtualenv venv -p python3 --no-site-packages

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


Guess you like

Origin www.cnblogs.com/petewell/p/11615008.html