python源代码编译(基于centos7)

来源:互联网 发布:集体智慧编程 高清 编辑:程序博客网 时间:2024/05/18 03:48

如何快速的搭建python源代码的开发环境?

基础环境:centos7.1

1、获取源代码

git镜像

python官方ftp服务器

以2.7.5为例子

wget https://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz


2、生成编译目录

你可用直接在解压的源码里面里面构建编译模块,也可用自己创建编译目录,推荐使用后者,比如

make ~/optimized

cd ~/optimized

${python-source}/configure --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --program-prefix=  --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-ipv6 --enable-shared --enable-unicode=ucs4 --with-dbmliborder=gdbm:ndbm:bdb --with-system-expat --with-system-ffi --with-dtrace --with-tapset-install-dir=/usr/share/systemtap/tapset --with-valgrind

python-source:python源代码的解压路径

编译之后会在~/optimized目录下面生成编译目录及工程Makefile文件。

3、编译、安装

编译

make 'EXTRA_CFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv  ' -j4

编译过程实际上是生成python解析器及其共享库的过程,默认编译过后会在编译目录下面生成python的c共享库及python解释器,如果这时候你不想执行安装步骤,以免污染系统python解释器,你可以通过在自己编译的python解释器前面加上动态库加载路径。

举个例子

LD_LIBRARY_PATH=~/optimized: ./python -E -c 'import sys ; from sysconfig import get_platform ; print get_platform()+"-"+sys.version[0:3]' 


安装

make install

安装的时候,除了会安装共享库以外,还会把Lib目录下面自带的python模块编译一遍安装到/usr/lib64/python2.7/


4、debug模式:

配置

${python-source}/configure --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --program-prefix= --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-ipv6 --enable-shared --enable-unicode=ucs4 --with-dbmliborder=gdbm:ndbm:bdb --with-system-expat --with-system-ffi --with-dtrace --with-tapset-install-dir=/usr/share/systemtap/tapset --with-valgrind --with-pydebug --with-tsc --with-count-allocs --with-call-profile

编译

make -s 'EXTRA_CFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv  ' -j4

安装

make install

可选:

在编译的时候可用设置编译优化选项

CFLAGS='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv '
CXXFLAGS='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv'
FFLAGS='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic -I/usr/lib64/gfortran/modules'
FCFLAGS='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic -I/usr/lib64/gfortran/modules'
LDFLAGS='-Wl,-z,relro   '

export FCFLAGS CFLAGS CXXFLAGS FFLAGS FCFLAGS LDFLAGS


0 0
原创粉丝点击