1 获取linux系统的版本信息
[root@ice ~]# cat /etc/redhat-release (或使用命令 more /etc/redhat-release)
CentOS Linux release 7.5.1804 (Core)
2 <本系统默认自带python2.7.5>
[root@ice ~]# python
Python 2.7.5 (default, Apr 11 2018, 07:36:10)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> (按Ctrl+D 结束)
3 因为后期要用到pip3,而pip依赖ssl环境,所以先安装openssl,openssl-devel
[root@ice ~]# yum -y install openssl openssl-devel (或写成 yum -y install openssl* )
[root@ice ~]#
rpm -qa openssl
openssl-1.0.2k-12.el7.x86_64
[root@ice ~]# rpm -qa|grep openssl (注意:rpm -e --nodeps openssl 移除的只是openssl-1.0.2k-12.el7.x86_64。剩下的千万不要移除,否则重新安装 openssl的时候会出问题,安装不上)
openssl-1.0.2k-12.el7.x86_64
openssl-libs-1.0.2k-12.el7.x86_64
openssl098e-0.9.8e-29.el7.centos.3.x86_64
xmlsec1-openssl-1.2.20-7.el7_4.x86_64
[root@ice ~]# rpm -qa|grep openssl-devel
[root@ice ~]# yum -y install openssl openssl-devel (或写成 yum -y install openssl* )
[root@ice ~]# icebox -v
3.7.1
[root@ice ~]# rpm -qa ice
[root@ice ~]# rpm -qa icebox
icebox-3.7.1-1.el7.x86_64
[root@ice ~]# rpm -qa |grep icebox
icebox-3.7.1-1.el7.x86_64
[root@ice ~]# rpm -qa |grep openssl-devel
openssl-devel-1.0.2k-12.el7.x86_64
[root@ice ~]# rpm -qa|grep openssl
openssl-perl-1.0.2k-12.el7.x86_64
openssl-1.0.2k-12.el7.x86_64
openssl-libs-1.0.2k-12.el7.x86_64
openssl098e-0.9.8e-29.el7.centos.3.x86_64
openssl-static-1.0.2k-12.el7.x86_64
openssl-devel-1.0.2k-12.el7.x86_64
xmlsec1-openssl-1.2.20-7.el7_4.x86_64
[root@ice ~]# python
Python 2.7.5 (default, Apr 11 2018, 07:36:10)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
4 下载编译安装python3.5,记的先下载gcc-c++!
[root@ice Python-3.5.2]# yum -y install gcc gcc-c++
若不安装合适的 c 编译器,则在 ./configure && make all && make install 的时候会报错:
安装 python3.5,并编译
[root@ice ~]# cd /usr/local
[root@ice local]# pwd
/usr/local
[root@ice local]# wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
[root@ice local]# ls
bin etc games ice_works include java lib lib64 libexec Python-3.5.2 Python-3.5.2.tgz sbin share src
[root@ice local]# tar -xf Python-3.5.2.tgz
[root@ice local]# cd Python-3.5.2
[root@ice Python-3.5.2]# ./configure && make all && make install (编译安装)
[root@ice local]# python3 (或 python3.5)
Python 3.5.2 (default,Jul 13 2018, 15:32:45)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
此时系统里有两个python版本,python2和python3。任意路径下输入命令 python或python2显示的是python2的版本信息;输入命令python3或python3.5显示的是python3的版本信息。
5 我喜欢并强烈推荐ipython,所以使用pip3安装ipython。ipython是一个强大的python的交互式shell。
pip3 install ipython
pip3安装其他组件
pip3 install Flask==0.12.2 requests==2.18.4
补充:
若提示 You are using pip version 8.1.1, However version 10.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. 则输入下面命令升级pip3版本。
[root@ice bin]# pip3 install --upgrade pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 128kB/s
Installing collected packages: pip
Found existing installation: pip 8.1.1
Uninstalling pip-8.1.1:
Successfully uninstalled pip-8.1.1
Successfully installed pip-10.0.1
[root@ice bin]# pip3 --version
pip 10.0.1 from /usr/local/lib/python3.5/site-packages/pip (python 3.5)
[root@ice bin]#