linux下python操作的一些命令
1.查看python当前版本以及安装路径
[root@localhost bin]# python -V Python 2.7.5 [root@localhost HMK]# whereis python python: /usr/bin/python /usr/bin/python2.7 /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /usr/share/man/man1/python.1.gz [root@localhost HMK]#
2.进入python命令终端
[root@localhost bin]# python Python 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
【Ctrl+D】即可退出终端
3.python2.7升级至python3.x
因为centos7中默认安装的是python2.7,有些环境需要依赖python2.7,所以这里只安装python3,不更改python2.7的相关配置
(1)下载python3安装包
切换到/usr/local,然后下载安装包
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz
(2)解压安装包
tar -xzvf Python-3.6.2.tgz
(3)编译安装
./configure --with-ssl (注意加上ssl,不然会导致pip无法使用)
make
make install
通过以上步骤即可完成安装,在使用python命令时,为了与python2.7区分,需要加上使用python3
比如在运行一个python文件时
[root@localhost HMK]# python3 demo.py