版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。

访问官网查看python 3.6.x 系列有什么安装包

因为是Centos6,前面安装3.7.x系列在SSL这块有些问题,考虑使用3.6.x系列看看。
访问官网下载地址:https://www.python.org/downloads/source/

安装系统依赖

[root@centos6 Python-3.6.8]# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel -y

下载python3.6.x的安装包

[root@centos6 opt]# wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz

安装过程

[root@centos6 opt]# tar -zxvf Python-3.6.8.tgz [root@centos6 Python-3.6.8]# ./configure --prefix=/usr/local/python3 [root@centos6 Python-3.6.8]# make && make install

设置环境

安装完毕之后,文件会在/usr/local/python3/bin/路径下。
[root@centos6 Python-3.6.8]# ls /usr/local/python3/bin/ 2to3 easy_install-3.6 idle3.6 pip3.6 pydoc3.6 python3.6 python3.6m python3-config pyvenv-3.6 2to3-3.6 idle3 pip3 pydoc3 python3 python3.6-config python3.6m-config pyvenv [root@centos6 Python-3.6.8]# [root@centos6 bin]# ./python3.6 Python 3.6.8 (default, Apr 23 2019, 14:53:03) [GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> exit() [root@centos6 bin]# [root@centos6 bin]# ./pip3 search redis redis (3.2.1) - Python client for Redis key-value store redis-completion (0.5.0) - autocomplete with redis
设置软连接
ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3.6
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
设置之后,就可以全局使用了,如下:
[root@centos6 bin]# ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3.6 [root@centos6 bin]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 [root@centos6 bin]# [root@centos6 bin]# cd ~ [root@centos6 ~]# ls anaconda-ks.cfg Desktop Documents Downloads gitbook install.log install.log.syslog Music netperf-2.6.0-2.gf.el6.x86_64.rpm Pictures Public Templates tmp Videos [root@centos6 ~]# python3.6 Python 3.6.8 (default, Apr 23 2019, 14:53:03) [GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> exit Use exit() or Ctrl-D (i.e. EOF) to exit >>> exit() [root@centos6 ~]# pip3 search redis redis (3.2.1) - Python client for Redis key-value store redis-completion (0.5.0) - autocomplete with redis kinto-redis (2.0.0) - Kinto Redis

升级pip3到最新版本

pip3 install --upgrade pip
[root@centos6 ~]# pip3 install --upgrade pip Collecting pip Downloading https://files.pythonhosted.org/packages/d8/f3/413bab4ff08e1fc4828dfc59996d721917df8e8583ea85385d51125dceff/pip-19.0.3-py2.py3-none-any.whl (1.4MB) 100% || 1.4MB 122kB/s Installing collected packages: pip Found existing installation: pip 18.1 Uninstalling pip-18.1: Successfully uninstalled pip-18.1 Successfully installed pip-19.0.3 [root@centos6 ~]#

安装ipython3

pip3 install ipython
安装完毕后,可以从/usr/local/python3/bin目录下找到ipython的二进制可执行文件。
[root@centos6 ~]# cd /usr/local/python3/bin [root@centos6 bin]# ls 2to3 easy_install-3.6 idle3.6 iptest3 ipython3 pip3 pydoc3 pygmentize python3.6 python3.6m python3-config pyvenv-3.6 2to3-3.6 idle3 iptest ipython pip pip3.6 pydoc3.6 python3 python3.6-config python3.6m-config pyvenv [root@centos6 bin]# ./ipython /usr/local/python3/lib/python3.6/site-packages/IPython/core/history.py:226: UserWarning: IPython History requires SQLite, your history will not be saved warn("IPython History requires SQLite, your history will not be saved") Python 3.6.8 (default, Apr 23 2019, 14:53:03) Type 'copyright', 'credits' or 'license' for more information IPython 7.4.0 -- An enhanced Interactive Python. Type '?' for help. In [1]:

配置ipython3的软链接

ln -s /usr/local/python3/bin/ipython /usr/bin/ipython3
[root@centos6 bin]# ln -s /usr/local/python3/bin/ipython /usr/bin/ipython3 [root@centos6 bin]# [root@centos6 bin]# cd ~ [root@centos6 ~]# [root@centos6 ~]# ls anaconda-ks.cfg Desktop Documents Downloads gitbook install.log install.log.syslog Music netperf-2.6.0-2.gf.el6.x86_64.rpm Pictures Public Templates tmp Videos [root@centos6 ~]# [root@centos6 ~]# ipython3 /usr/local/python3/lib/python3.6/site-packages/IPython/core/history.py:226: UserWarning: IPython History requires SQLite, your history will not be saved warn("IPython History requires SQLite, your history will not be saved") Python 3.6.8 (default, Apr 23 2019, 14:53:03) Type 'copyright', 'credits' or 'license' for more information IPython 7.4.0 -- An enhanced Interactive Python. Type '?' for help. In [1]:

Centos6 对于python3的兼容性

经过了Centos6对于python 3.7.x 和python 3.6.x 的安装对比,还是使用python 3.6.x的兼容性最好。