首页 > 代码库 > CentOS6.5 64位系统安装32位python
CentOS6.5 64位系统安装32位python
CentOS6.5 自带gcc 4.4.7和python 2.6.6
提醒:我使用的是root用户,如果非root用户,就在指令前面都加上sudo吧
首先保证gcc可以将代码编译成32位,使用yum安装32位编译环境
#yum install libstdc++-devel.i686 glibc.i686 libgcc.i686 libstdc++.i686 glibc-devel.i686
# yum -y install glibc-devel
# yum -y install glibc-devel.i686
# yum install libstdc++-devel.i686
环境安装完成后,简单测试是否可以编译32位程序 例如 #gcc -m32 test.c,编译完成无问题
32位编译环境构建完成后,使用python2.7.7源码进行编译安装
在编译源码前需要安装下面的环境
#yum install libgcc.i686 glibc-devel.i686 glibc.i686 zlib-devel.i686
#yum install readline-devel.i686 gdbm-devel.i686 openssl-devel.i686 ncurses-devel.i686
#yum install tcl-devel.i686 db4-devel.i686 bzip2-devel.i686
到此准备工作已经完成开始通过源码进行安装32位python,源码我放在/usr/local/src中
#cd /usr/local/src
#wget http://www.python.org/ftp/python/2.7.7/Python-2.7.7.tgz
#tar xzvf Python-2.7.7.tgz
#cd Python-2.7.7/
#mkdir -p /usr/local/Python-2.7
#CFLAGS=-m32 LDFLAGS=-m32 ./configure --prefix=/usr/local/Python2.7 --enable-shared LD_RUN_PATH=/usr/local/lib
#make
#make install
编译安装完成后可以使用
#file /usr/local/Python2.7/bin/python2.7
显示为
/usr/local/Python2.7/bin/python2.7: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped
说明python2.7 32位已经安装成功
然后设置软件连接和配置环境,不分先后
设置软连接
#mv /usr/bin/python /usr/bin/python_old
#ln -s /usr/local/python27/bin/python /usr/bin/python
yum依赖于python2.6.6,通过上面的设置后yum无法使用
#vi /usr/bin/yum
将第一行/usr/bin/python 修改成/usr/bin/python_old,保存退出,这样yum就可以正常使用了
配置环境
# echo $PATH
/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin
# PATH="$PATH":/usr/local/Python2.7/bin
# echo $PATH
/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin:/usr/local/Python2.7/bin
运行#python,如果出现error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory错误
#vi /etc/ld.so.conf
将python2.7的lib库添加进去,我的是/usr/local/Python2.7/lib,也就是安装目录中的lib的路径,保存退出
#ldconfig -v
到此python2.7 32位就安装完成了
CentOS6.5 64位系统安装32位python