(1)、python版本安装(多版本共存)

一曲冷凌霜 提交于 2020-04-27 18:48:06
1、官网下载python3.6版本的安装包: wget  https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
2、安装zlib-devel(后面安装pip也要用到这个依赖包)
yum install -y zlib-devel
yum install -y gcc
3、解压这个包:
tar zxvf Python-3.6.5.tgz
4、检测系统配置,生成编译所需要makefile文件,系统是否满足安装软件的依赖关系:指定安装目录。
makefile文件里包含里用什么编码器(gcc还是cc),编译参数等信息
./configure --prefix=/usr/local/python3 --with-ssl
4、编译这个文件:根据makefile中生成的文件进行编译,生成可执行文件。
[root@fenye Python-3.6.5]# make
5、编译安装:把make生成的可执行文件安装到目录下,不执行则无法启动应用。
[root @fenye Python-3.6.5]# make install
6、建立软连接:
[root@fenye Python-3.6.5]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
[root@fenye Python-3.6.5]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

注释:由于python里面集成了pip,pip无需单独安装;

7、查看系统python版本及pip版本:
[root@fenye Python-3.6.5]# python --version
Python 2.7.5
[root@fenye Python-3.6.5]# python3 --version
Python 3.6.5
[root@fenye Python-3.6.5]# pip --version
pip 19.1.1 from /usr/lib/python2.7/site-packages/pip (python 2.7)
[root@fenye Python-3.6.5]# pip3 --version
pip 9.0.3 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)

注释:安装2.7版本的pip,系统自带的yum源里没有这个包,需要安装扩展源:

yum install -y epel-release

yum -y install python-pip

ipython安装:

[root@fenye ~]# pip install ipython #安装2.7的ipython
[root@fenye ~]# pip3 install ipython #安装3.6的ipython
[root@fenye ~]# ipython
ipython ipython3
[root@fenye ~]# ipython
Python 2.7.5 (default, Aug 7 2019, 00:51:29)
Type "copyright", "credits" or "license" for more information.
[root@fenye ~]# ipython3
Python 3.6.5 (default, Apr 14 2020, 12:37:12)
Type 'copyright', 'credits' or 'license' for more information

ipython3安装完后启动时,报如下错误,无法保存命令历史:

[root@fenye ~]# 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.5 (default, Apr 14 2020, 12:37:12)
这是因为再编译python3时,没有安装sqlite-devel,所有会发出这个警告:
此时可以通过以下两个方式解决:
1、yum安装sqlite-devel,然后重新编译python3
[root @fenye Python-3.6.5]# yum install -y sqlite-devel
编译方法第一步介绍
2、下载sqilte-devel并编译安装,然后重新编译python3
编译方法第一步介绍
[root@fenye src]# wget http://www.sqlite.org/sqlite-autoconf-3071401.tar.gz
./configure --prefix=/usr/local/
make
make install

附记:

命令历史里显示具体日期:
[root @fenye src]# vim /etc/profile
HISTSIZE=2000
HISTTIMEFORMAT=" %Y-%m-%d %H-%M-%S "
刷新并查看
[root@fenye src]# source /etc/profile
[root@fenye src]# history |head -n10
1 2020-04-14 13-49-36 LS
2 2020-04-14 13-49-36 ls
3 2020-04-14 13-49-36 df
4 2020-04-14 13-49-36 ls
5 2020-04-14 13-49-36 vim /etc/hosts
6 2020-04-14 13-49-36 vim /etc/networks
7 2020-04-14 13-49-36 hostname
8 2020-04-14 13-49-36 vim /etc/sysconfig/network
9 2020-04-14 13-49-36 vim /etc/ssh/sshd_config
10 2020-04-14 13-49-36 service sshd restart

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!