虽然,这个并不难,但因为对linux不熟悉,公司电脑又限制了部分资源的下载,走了许多弯路。此文经验证是可用的。
本文以安装python3.5.2为例子
1、从Python官网下载
wgethttps://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
2、解压Python-3.5.2.tgz
tar xzf Python-3.5.2.tgz
3、配置编译安装python3
安装python需要的库:
yum -y install gcc gcc-c++ openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
cd Python-3.5.2/
进行配置,把安装的python3.5.2的目录放到/usr/local/python3.5里面
./configure --prefix=/usr/local/python3
完成后执行echo $?返回是0则配置没有错误,继续进行下一步编译
make -j2
完成后执行echo $?返回是0则编译没有错误,继续进行下一步安装
make install -j2
ls /usr/local/python3/bin/python3.5
ln -s /usr/local/python3/bin/python3.5 /usr/bin/python3
ls /usr/local/python3/bin/pip3
这里会出现两种情况,如果有这个文件,则直接到(2):
tar xzf pip-8.1.2.tar.gz
cd pip-8.1.2/
python2 setup.py install
如果出现以下提示:
Traceback (mostrecent call last):
File "setup.py",line 6,in<module>
from setuptools import setup,find_packages
ImportError: Nomodule named setuptools
则需要先安装setuptools,再安装pip
tar xzf setuptools-25.2.0.tar.gz
cd setuptools-25.2.0/
python3setup.py install
最后提示Finished processing dependencies forsetuptools==25.2.0
则安装setuptools成功
再回去pip-8.1.2目录
执行python3setup.py install安装
最后提示Finished processing dependencies for pip==8.1.2
则pip安装成功
ls查看确认
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
4、验证安装
输入python3命令,出现以下则成功
Python 3.5.2(default,Aug 31 2016,07:34:34)
[GCC 4.8.5 20150623(Red Hat 4.8.5-4)] onLinux
Type"help","copyright","credits" or"license" for more information.
>>>
输入pip3 -V命令,出现以下则成功
pip 8.1.1 from /usr/local/python3/lib/python3.5/site-packages (python 3.5)
原文链接:https://www.f2er.com/centos/379613.html