今日在centos上编译python5.3.1时,记录遇到的小插曲:
按照顺序,从一开始描述:
- 下载
wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz
- 编译前环境准备
yum groupinstall "Development tools"
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
- 编译
tar -zxvf Python-3.5.1.tgz
cd Python-3.5.1
./configure --prefix=/usr/local/python3
(注意:python3目录不是必须加的,若不加,则下文中的python3路径也要去掉)
make
4.在make的时候,遇到错误
python-config: $(srcdir)/Misc/python-config.in Misc/python-config.sh sed -e "s,@EXENAME@,$(BINDIR)/python$(LDVERSION)$(EXE)," < $(srcdir)/Misc/python-config.in >python-config.py
# Replace makefile compat. variable references with shell script compat. ones; $(VAR) -> ${VAR} sed -e 's,$$(([A-Za-z0-9_]*)),$${\1},g' < Misc/python-config.sh >python-config
# On Darwin, always use the python version of the script, the shell
# version doesn't use the compiler customizations that are provided
# in python (_osx_support.py).
if test `uname -s` = Darwin;then
cp python-config.py python-config;
fi
于是在网上找资料,终于在这个博文里找到帮助
- 现将系统原有的 /usr/bin/python 删掉
- 再运行make clean
- 再make 以及 make install 就完成了
不过这样做的后果就是,系统原本依赖的 /usr/bin/phthon会出现错误,典型的例子就是运行 yum install 的时候,会出现 /usr/bin/python no such file的问题,于是我这么解决:
- cp /usr/bin/python2.6 /usr/bin/python
这样yum又可以正常运行了(centos6.5系统默认的python是2.6版本)
不过感觉还是先备份/usr/bin/python,再删除/usr/bin/python,编译玩py3.5.1后再恢复/usr/bin/python, 这个是后来才想起的(>﹏<。)~……
5.软连接
ln -s /usr/local/python3.5.1/bin/python3 /usr/bin/python3
6.配置库
echo /usr/local/Python3.5.1/lib >> /etc/ld.so.conf.d/local.conf
ldconfig
7.检测
python3 --version
文章参考的资源链接地址:
http://blog.csdn.net/cao812755156/article/details/52389166
http://www.linuxidc.com/Linux/2015-11/124908.htm
ps:花絮
另外我找到了另一篇的方法,只是我觉得这样子貌似挺不方便的,提供个链接瞧瞧:http://blog.sina.com.cn/s/blog_54f82cc201015yvu.html 不过倒是领悟到了一丝丝的东西~~
原话的描述是:这个错误是因为python的版本不匹配,只要在/usr/bin/yum中把第一行的#!/usr/bin/python改成#!/usr /bin/python2.4就可以啦~当然,我是指路径对的情况下,毕竟通常linux下的python默认版本都是2.4,当然,例外不算。