centos6.5环境下安装python2.7
解压python源码包tar -xf Python-2.7.6.tar.xz
进入软件包目录
cd Python-2.7.6
添加配置项
./configure --prefix=/usr/local/python27
编译
make
报错
Python build finished, but the necessary bits to build these modules were not found:
_bsddb _sqlite3 _ssl
_tkinter bsddb185 bz2
dbm dl gdbm
imageop sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
方法:
将centos6.5的光盘挂载在/mnt/cdrom目录下
mkdir /mnt/cdrom
mount /dev/cdrom /mnt/cdrom
cd /mnt/cdrom/Packages/
提示缺少readline-devel包,安装readline-devel包的时候提示依赖ncurses-devel
rpm -ivh ncurses-devel-5.7-3.20090208.el6.x86_64.rpm
rpm -ivh readline-devel-6.0-4.el6.x86_64.rpm
删除相关的目录重新配置并编译
rm -rf /usr/local/python27
./configure --prefix=/usr/local/python27
make
make install
后面继续报缺少依赖包直接忽略
②安装ipython1.2.1
tar -xf ipython-1.2.1.tar.gz
cd ipython-1.2.1
使用python27对ipython进行编译
/usr/local/python27/bin/python2.7 setup.py build
编译成功执行安装
/usr/local/python27/bin/python2.7 setup.py install
如果安装成功则在/usr/local/python27/bin目录下有一个ipython文件
ls /usr/local/python27/bin/
######################
将python和ipython链接到bin目录下,方便调用(直接输入python和ipython命令即可)
ln -sv /usr/local/python27/bin/python2.7 /usr/bin/python27
ln -sv /usr/local/python27/bin/ipython /usr/bin/
centos6.5环境python3.5的安装
安装相关依赖:
yum -y install xz wget gcc make gdbm-devel openssl-devel sqlite-devel zlib-devel bzip2-devel
安装python3:
wget http://mirrors.sohu.com/python/3.5.2/Python-3.5.2.tar.xz
tar -xf Python-3.5.2.tar.xz
cd Python-3.5.2
./configure --enable-shared --enable-loadable-sqlite-extensions --with-zlib
make && make install
添加python3命令:
ln -sv /usr/local/bin/python3.5 /usr/bin/python3
vim /etc/ld.so.conf
/usr/local/lib # 新增库文件路径
include ld.so.conf.d/*.conf
# 使配置库生效
/sbin/ldconfig
版本检测
# python3 -V
Python 3.5.2
以后直接运行python3就可以通过python3.5.2版本执行命令了