首先系统自带的python是python2
我们需要安装一个python3(这里的所有源码包都可以在环境中准备好,这样没有网也可以进行安装)
安装python
1.安装环境
# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-develreadline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel sqlite-devel
2.下载包
wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
3.解压包
tar -zxvf Python-3.6.1.tgz
4.创建安装目录,进入解压后的包,制定安装路径进行安装
mkdir -p /usr/local/python3 cd Python-3.6.1 ./configure --prefix=/usr/local/python3
报错
[root@bogon Python-3.6.1]# ./configure --prefix=/usr/local/python3
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for python3.6... no
checking for python3... no
checking for python... python
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... linux
checking for --without-gcc... no
checking for --with-icc... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/Python-3.6.1':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
由于本机缺少gcc编译环境
1、通过yum安装gcc编译环境:yum install -y gcc
5.编译安装
make && make install
6.创建软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
这样在命令行中输入python代表python2,输入python3代表python3
-----------------------------------------------------------------------------------------------------
./pip3 install --upgrade setuptools pip
python默认的pip版本和setuptools版本比较旧,如果有网,可以在线更新,下面记录一下离线更新
----------------------------------------------------------------------------------------------------
安装pip3
1.首先安装setuptools(安装到python3里,安装完成后可以删除源码包)
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-40.6.2.zip#md5=c607dd118eae682c44ed146367a17e26 unzip setuptools-40.6.2.zip
cd setuptools-40.6.2
python3 setup.py build
python3 setup.py install
2.安装pip3
wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-18.1.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb tar -zxvf pip-18.1.tar.gz cd pip-8.0.2 python3 setup.py build python3 setup.py install
3.安装完成之后我们再来看下python的bin目录下都有什么东西吧,发现有pip
创建软连接
ln -s /usr/local/python3/bin/pip /usr/bin/pip