如果本机安装了python2,尽量不要管他,使用python3运行python脚本就好,因为可能有程序依赖目前的python2环境,
比如yum!!!!!
不要动现有的python2环境!
一. 安装准备
1. 安装依赖环境
# 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
2.下载Python3
从官网下载相应的Python版本,目前最新版本为Python3.6.4,点击下载。
也可以通过如下命令下载:wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
3. 安装第三方包
在Python下载目录依次运行如下命令:
[root@cdh1 opt]# tar zxvf Python-3.6.4.tgz
[root@cdh1 opt]# cd Python-3.6.4
个人习惯安装在/usr/local/python3(具体安装位置看个人喜好)
创建目录:
[root@cdh1 Python-3.6.4]# mkdir -p /usr/local/python3
[root@cdh1 Python-3.6.4]# ./configure --prefix=/usr/local/python3
[root@cdh1 Python-3.6.4]# make
[root@cdh1 Python-3.6.4]# make install
make是一个编译命令,如果make的时候出现以下情况,那就是没有找到makefile,你看下configure的时候有没有报错呀,是不是提示有什么依赖的包没有装,先把依赖的包装了,再configure,试试,看有没有makefile
安装依赖包 Python3.6安装报错 configure: error: no acceptable C compiler found in $PATH,原因是由于本机缺少gcc编译环境
[root@master ~]#./configure --prefix=/usr/local/python3.6
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for --enable-universalsdk... no
checking for --with-universal-archs... 32-bit
checking MACHDEP... linux
checking for --without-gcc... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/pythonSoft/Python-3.3.4':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
-
(1)通过yum安装gcc编译环境:yum install -y gcc
-
(2)本机没有安装yum功能,可下载gcc安装包:https://gcc.gnu.org/
[root@cdh1 Python-3.6.4]# yum install -y gcc
然后再make
[root@cdh1 Python-3.6.4]# make
[root@cdh1 Python-3.6.4]# make install
4. 建立python3的软链
[root@cdh1 Python-3.6.4]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
5.并将/usr/local/python3/bin加入PATH
[root@cdh1 Python-3.6.4]# vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH
按ESC,输入:wq回车退出。
6.修改完记得执行行下面的命令,让上一步的修改生效:
[root@cdh1 Python-3.6.4]# source ~/.bash_profile
7.检查Python3及pip3是否正常可用:
[root@cdh1 Python-3.6.4]# python3 -V
Python 3.6.4
[root@cdh1 Python-3.6.4]# pip3 -V
pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)
不行的话在创建一下pip3的软链接(我也不清楚这一步有什么用)
# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
网友评论