首先我们需要安装Python的依赖环境,不然在安装过程中容易报错
[root@docker-02 ~]# yum install gcc-c++
[root@docker-02 ~]# yum -y install -y lsb
[root@docker-02 ~]# yum -y install -y libXScrnSaver
[root@docker-02 ~]# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
在这里我们首先打开官网Python.org.在 Downloads
目录下的Source code
中进行查看Python
的版本及其下载链接。这里我们选择3.7.0版本,翻着页面下方Files
表单,选择Gzipped source tarball
右键复制链接地址
[root@docker-02 ~]# wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
[root@docker-02 ~]# tar -xvzf Python-3.7.0.tgz
[root@docker-02 ~]# cd Python-3.7.0/
[root@docker-02 Python-3.7.0]# ./configure --prefix=/usr/python3 --enable-optimizations --with-ssl
[root@docker-02 Python-3.7.0]# make && make install
[root@docker-02 Python-3.7.0]# ln -s /usr/python3/bin/python3 /usr/bin/python3
[root@docker-02 Python-3.7.0]# ln -s /usr/python3/bin/pip3 /usr/bin/pip3
[root@docker-02 Python-3.7.0]# pip3 install --upgrade pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/30/db/9e38760b32e3e7f40cce46dd5fb107b8c73840df38f0046d8e6514e675a1/pip-19.2.3-py2.py3-none-any.whl (1.4MB)
100% |████████████████████████████████| 1.4MB 461kB/s
Installing collected packages: pip
Found existing installation: pip 10.0.1
Uninstalling pip-10.0.1:
Successfully uninstalled pip-10.0.1
Successfully installed pip-19.2.3
现在就可以用python3
命令进入Python3.7啦,也可以用pip3安装库了
[root@docker-02 Python-3.7.0]# python3 --version
Python 3.7.0
[root@docker-02 Python-3.7.0]# pip3 install Django
Collecting Django
Downloading https://files.pythonhosted.org/packages/b2/79/df0ffea7bf1e02c073c2633702c90f4384645c40a1dd09a308e02ef0c817/Django-2.2.6-py3-none-any.whl (7.5MB)
|████████████████████████████████| 7.5MB 750kB/s
Collecting pytz (from Django)
Downloading https://files.pythonhosted.org/packages/e7/f9/f0b53f88060247251bf481fa6ea62cd0d25bf1b11a87888e53ce5b7c8ad2/pytz-2019.3-py2.py3-none-any.whl (509kB)
|████████████████████████████████| 512kB 31.9MB/s
Collecting sqlparse (from Django)
Downloading https://files.pythonhosted.org/packages/ef/53/900f7d2a54557c6a37886585a91336520e5539e3ae2423ff1102daf4f3a7/sqlparse-0.3.0-py2.py3-none-any.whl
Installing collected packages: pytz, sqlparse, Django
Successfully installed Django-2.2.6 pytz-2019.3 sqlparse-0.3.0