编译Python2.6.6并需要外部软件包wxPython、setuptools等。。。在Ubuntu中

编译Python2.6.6并需要外部软件包wxPython、setuptools等。。。在Ubuntu中,python,ipython,ld,rpath,tcmalloc,Python,Ipython,Ld,Rpath,Tcmalloc,我使用GooglePerf工具(tcmalloc)库编译了Python2.6.6,以消除默认2.6.5中的一些内存问题。在运行2.6.6之后,它似乎不起作用,因为我认为Ubuntu中默认的2.6.5安装有问题。从软件通道安装的二进制文件(如wxPython和setuptools)都不能在2.6.6中正常工作。这些需要重新编译吗?任何其他使其顺利运行的建议。我仍然可以在不更改路径的情况下将2.6.5设置为默认值吗?路径首先在usr/local/bin中查找。如果您从repos编译了2.6.6并安装

我使用GooglePerf工具(tcmalloc)库编译了Python2.6.6,以消除默认2.6.5中的一些内存问题。在运行2.6.6之后,它似乎不起作用,因为我认为Ubuntu中默认的2.6.5安装有问题。从软件通道安装的二进制文件(如wxPython和setuptools)都不能在2.6.6中正常工作。这些需要重新编译吗?任何其他使其顺利运行的建议。我仍然可以在不更改路径的情况下将2.6.5设置为默认值吗?路径首先在usr/local/bin中查找。

如果您从repos编译了2.6.6并安装了2.6.5,那么ubuntu在查找您使用的python时会遇到冲突


我将此标记为转移到Superuser。

一个好的一般经验法则是,除了其他系统管理脚本之外,任何软件开发都不要使用默认系统安装的Python。这适用于所有Unix,包括Linux和OS/X

相反,使用所需的库(Python和C)构建一个好的由您控制的Python发行版,并将此tarball安装在非系统目录中,如/opt/devpy或/data/package/Python或/home/Python。既然2.7.2可用,为什么还要乱用2.6呢

在构建它时,请确保其所有依赖项都位于其自己的目录树(RPATH)中,并且所有系统依赖项(.so文件)都复制到其目录树中。这是我的版本。如果只运行整个shell脚本,则可能无法工作。我总是将这些部分复制并粘贴到终端窗口中,并验证每个步骤是否正常工作。确保您的终端属性设置为允许很多行的回滚,或者一次只粘贴几行

(实际上,在做了一些调整之后,我认为这可能可以作为脚本运行,但是我建议使用类似于
/pybuild.sh>pylog 2>&1
的东西,这样您就可以梳理输出并验证构建的所有内容是否正常

这是建立在64位Ubuntu上的

#!/bin/bash

shopt -s compat40

export WGET=echo
#uncomment the following if you are running for the first time
export WGET=wget

sudo apt-get -y install build-essential
sudo apt-get -y install zlib1g-dev libxml2-dev libxslt1-dev libssl-dev libncurses5-dev 
sudo apt-get -y install libreadline6-dev autotools-dev autoconf automake libtool
sudo apt-get -y install libsvn-dev mercurial subversion git-core
sudo apt-get -y install libbz2-dev libgdbm-dev sqlite3 libsqlite3-dev
sudo apt-get -y install curl libcurl4-gnutls-dev
sudo apt-get -y install libevent-dev libev-dev librrd4 rrdtool
sudo apt-get -y install uuid-dev libdb4.8-dev memcached libmemcached-dev 
sudo apt-get -y install libmysqlclient-dev libexpat1-dev 

cd ~
$WGET 'http://code.google.com/p/google-perftools/downloads/detail?name=google-perftools-1.7.tar.gz'
$WGET http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
tar zxvf Python-2.7.2.tgz
cd Python-2.7.2

#following is needed if you have an old version of Mercurial installed
#export HAS_HG=not-found

# To provide a uniform build environment
unset PYTHONPATH PYTHONSTARTUP PYTHONHOME PYTHONCASEOK PYTHONIOENCODING
unset LD_RUN_PATH LD_LIBRARY_PATH LD_DEBUG LD_TRACE_LOADED_OBJECTS 
unset LD_PRELOAD SHLIB_PATH LD_BIND_NOW LD_VERBOSE

## figure out whether this is a 32 bit or 64 bit system
m=`uname -m`
if [[ $m =~ .*64 ]]; then
   export CC="gcc -m64" 
   NBITS=64
elif [[ $m =~ .*86 ]]; then
   export CC="gcc -m32"
   NBITS=32
else # we are confused so bail out
   echo $m
   exit 1
fi

# some stuff related to distro independent build
# extra_link_args = ['-Wl,-R/data1/python27/lib']
#--enable-shared and a relative 
# RPATH[0] (eg LD_RUN_PATH='${ORIGIN}/../lib')

export TARG=/data1/packages/python272
export TCMALLOC_SKIP_SBRK=true
#export CFLAGS='-ltcmalloc' # Google's fast malloc
export COMMONLDFLAGS='-Wl,-rpath,\$$ORIGIN/../lib -Wl,-rpath-link,\$$ORIGIN:\$$ORIGIN/../lib:\$$ORIGIN/../../lib -Wl,-z,origin -Wl,--enable-new-dtags'
# -Wl,-dynamic-linker,$TARG/lib/ld-linux-x86-64.so.2
export LDFLAGS=$COMMONLDFLAGS
./configure --prefix=$TARG --with-dbmliborder=bdb:gdbm --enable-shared --enable-ipv6

# if you have ia32-libs installed on a 64-bit system
#export COMMONLDFLAGS="-L/lib32 -L/usr/lib32 -L`pwd`/lib32 -Wl,-rpath,$TARG/lib32 -Wl,-rpath,$TARG/usr/lib32"

make
# ignore failure to build the following since they are obsolete or deprecated
# _tkinter bsddb185 dl imageop sunaudiodev 

#install it and collect any dependency libraries - not needed with RPATH
sudo mkdir -p $TARG
sudo chown `whoami`.users $TARG
make install

# collect binary libraries ##REDO THIS IF YOU ADD ANY ADDITIONAL MODULES##
function collect_binary_libs {
cd $TARG
find . -name '*.so' | sed 's/^/ldd -v /' >elffiles
echo "ldd -v bin/python" >>elffiles
chmod +x elffiles
./elffiles | sed 's/.*=> //;s/ .*//;/:$/d;s/^              *//' | sort -u | sed 's/.*/cp -L & lib/' >lddinfo
# mkdir lib
chmod +x lddinfo
./lddinfo
cd ~
}
collect_binary_libs

#set the path
cd ~
export PATH=$TARG/bin:$PATH

#installed setuptools
$WGET http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
chmod +x setuptools-0.6c11-py2.7.egg
./setuptools-0.6c11-py2.7.egg

#installed virtualenv
tar zxvf virtualenv-1.6.1.tar.gz
cd virtualenv-1.6.1
python setup.py install
cd ~

# created a base virtualenv that should work for almost all projects
# we make it relocatable in case its location in the filesystem changes.
cd ~
python virtualenv-1.6.1/virtualenv.py /data1/py27base # first make it
python virtualenv-1.6.1/virtualenv.py --relocatable  /data1/py27base #then relocatabilize

# check it out
source ~/junk/bin/activate
python --version

# fill the virtualenv with useful modules
# watch out for binary builds that may have dependency problems

export LD_RUN_PATH='\$$ORIGIN:\$$ORIGIN/../lib:\$$ORIGIN/../../lib'
easy_install pip
pip install cython
pip install lxml
pip install httplib2
pip install python-memcached
pip install amqplib
pip install kombu
pip install carrot
pip install py_eventsocket
pip install haigha

# extra escaping of $ signs
export LDFLAGS='-Wl,-rpath,\$\$$ORIGIN/../lib:\$\$$ORIGIN/../../lib -Wl,-rpath-link,\$\$$ORIGIN/../lib -Wl,-z,origin -Wl,--enable-new-dtags'
# even more complex to build this one since we need some autotools and
# have to pull source from a repository
mkdir rabbitc
cd rabbitc
hg clone http://hg.rabbitmq.com/rabbitmq-codegen/
hg clone http://hg.rabbitmq.com/rabbitmq-c/
cd rabbitmq-c
autoreconf -i
make clean
./configure --prefix=/usr
make
sudo make install
cd ~

# for zeromq we get the latest source of the library
$WGET http://download.zeromq.org/zeromq-2.1.7.tar.gz
tar zxvf zeromq-2.1.7.tar.gz
cd zeromq-2.1.7
make clean
./configure --prefix=/usr
make
sudo make install
cd ~
# need less escaping of $ signs
export LDFLAGS='-Wl,-rpath,\$ORIGIN/../lib:\$ORIGIN/../../lib -Wl,-rpath-link,\$ORIGIN/../lib -Wl,-z,origin -Wl,--enable-new-dtags'
pip install pyzmq
pip install pylibrabbitmq # need to build C library and install first
pip install pylibmc
pip install pycurl
export LDFLAGS=$COMMONLDFLAGS


pip install cherrypy
pip install pyopenssl # might need some ldflags on this one?
pip install diesel
pip install eventlet
pip install fapws3
pip install gevent
pip install boto
pip install jinja2
pip install mako
pip install paste
pip install twisted
pip install flup
pip install pika
pip install pymysql
# pip install py-rrdtool # not on 64 bit???
pip install PyRRD
pip install tornado
pip install redis

# for tokyocabinet we need the latest source of the library
$WGET http://fallabs.com/tokyocabinet/tokyocabinet-1.4.47.tar.gz
tar zxvf tokyocabinet-1.4.47.tar.gz
cd tokyocabinet-1.4.47
make clean
./configure --prefix=/usr --enable-devel
make
sudo make install
cd ..
$WGET http://fallabs.com/tokyotyrant/tokyotyrant-1.1.41.tar.gz
tar zxvf tokyotyrant-1.1.41.tar.gz
cd tokyotyrant-1.1.41
make clean
./configure --prefix=/usr --enable-devel
make
sudo make install
cd ..
pip install tokyo-python
pip install solrpy
pip install pysolr
pip install sunburnt
pip install txamqp
pip install littlechef
pip install PyChef
pip install pyvb
pip install bottle
pip install werkzeug
pip install BeautifulSoup
pip install XSLTools
pip install numpy
pip install coverage
pip install pylint
# pip install PyChecker  ???
pip install pycallgraph
pip install mkcode
pip install pydot
pip install sqlalchemy
pip install buzhug
pip install flask
pip install restez
pip install pytz
pip install mcdict
# need less escaping of $ signs

pip install py-interface
# pip install paramiko # pulled in by another module
pip install pexpect

# SVN interface
$WGET http://pysvn.barrys-emacs.org/source_kits/pysvn-1.7.5.tar.gz
tar zxvf pysvn-1.7.5.tar.gz
cd pysvn-1.7.5/Source
python setup.py backport
python setup.py configure
make
cd ../Tests
make
cd ../Sources
mkdir -p $TARG/lib/python2.7/site-packages/pysvn
cp pysvn/__init__.py $TARG/lib/python2.7/site-packages/pysvn
cp pysvn/_pysvn_2_7.so $TARG/lib/python2.7/site-packages/pysvn
cd ~

# pip install protobuf #we have to do this the hard way
$WGET http://protobuf.googlecode.com/files/protobuf-2.4.1.zip
unzip protobuf-2.4.1.zip
cd protobuf-2.4.1
make clean
./configure --prefix=/usr
make
sudo make install
cd python
python setup.py install
cd ~

pip install riak
pip install ptrace
pip install html5lib
pip install metrics

#redo the "install binary libraries" step
collect_binary_libs

# link binaries in the lib directory to avoid search path errors and also
# to reduce the number of false starts to find the library
for i in `ls $TARG/lib/python2.7/lib-dynload/*.so`
do
ln -f $i $TARG/lib/`basename $i`
done
# for the same reason link the whole lib directory to some other places in the tree
ln -s ../.. $TARG/lib/python2.7/site-packages/lib

# bundle it up and save it for packaging
cd /
tar cvf - .$TARG |gzip >~/py272-$NBITS.tar.gz
cd ~

# after untarring on another machine, we have a program call imports.py which imports 
# every library as a quick check that it works. For a more positive check, run it like this
# strace -e trace=stat,fstat,open python imports.py >strace.txt 2>&1 
# grep -v ' = -1' strace.txt |grep 'open(' >opens.txt
# sed <opens.txt 's/^open("//;s/".*//' |sort -u |grep -v 'dynload' |grep '\.so' >straced.txt
# ls -1d /data1/packages/python272/lib/* |sort -u >lib.txt
# then examine the strace output to see how many places it searches before finding it.
# a successful library load will be a call to open that doesn't end with ' = -1'
# If it takes too many tries to find a particular library, then another symbolic link may 
# be a good idea
!/bin/bash
shopt-s-40
导出WGET=echo
#如果您是第一次运行,请取消对以下内容的注释
导出WGET=WGET
sudo apt get-y安装构建必需
sudo apt get-y安装zlib1g dev libxml2 dev libxslt1 dev libssl dev libncurse5 dev
sudo apt get-y安装libreadline6 dev autotools dev autoconf automake libtool
sudo apt get-y安装libsvn dev mercurial subversion git core
sudo apt get-y安装libbz2 dev libgdbm dev sqlite3 libsqlite3 dev
sudo apt get-y安装curl libcurl4 gnutls dev
sudo apt get-y安装libevent dev libev dev librrd4 rrdtool
sudo apt get-y安装uuid dev libdb4.8-dev memcached libmemcached dev
sudo apt get-y安装libmysqlclient dev libexpat1 dev
光盘~
$WGET'http://code.google.com/p/google-perftools/downloads/detail?name=google-perftools-1.7.tar.gz'
$WGEThttp://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
tar zxvf Python-2.7.2.tgz
cd Python-2.7.2
#如果您安装了旧版本的Mercurial,则需要执行以下操作
#导出已\u HG=未找到
#提供统一的构建环境
未设置PYTHONPATH PYTHONSTARTUP PYTHONHOME PYTHONCASEOK pythoneoding
取消设置LD_运行路径LD_库路径LD_调试LD_跟踪加载的对象
取消设置LD\u预加载SHLIB\u路径LD\u绑定\u现在LD\u详细
##确定这是32位还是64位系统
m=`uname-m`
如果[[$m=~*64]];则
导出CC=“gcc-m64”
NBITS=64
elif[$m=~*86]];然后
导出CC=“gcc-m32”
NBITS=32
否则,我们就糊涂了,所以滚开吧
回音万元
出口1
fi
#一些与发行版独立构建相关的东西
#额外链接参数=['-Wl,-R/data1/python27/lib']
#--启用共享和相对
#RPATH[0](例如LD_RUN_PATH='${ORIGIN}/./lib')
导出target=/data1/packages/python272
导出TCMALLOC\u SKIP\u SBRK=true
#export CFLAGS='-ltcmalloc'#谷歌的快速malloc
导出COMMONLDFLAGS='-Wl,-rpath,\$$ORIGIN/./lib-Wl,-rpath链接,\$$ORIGIN:\$$ORIGIN/./lib:\$$ORIGIN/./../lib-Wl,-z,ORIGIN-Wl,--启用新的dtags'
#-Wl,-动态链接器,$TARG/lib/ld-linux-x86-64.so.2
导出LDFLAGS=$COMMONLDFLAGS
./configure--prefix=$TARG--with dbmliborder=bdb:gdbm--enable-shared--enable-ipv6
#如果在64位系统上安装了ia32 LIB
#export COMMONLDFLAGS=“-L/lib32-L/usr/lib32-L`pwd`/lib32-Wl,-rpath,$TARG/lib32-Wl,-rpath,$TARG/usr/lib32”
制作
#忽略生成以下内容的失败,因为它们已过时或不推荐使用
#_tkinter bsddb185 dl imageop sunaudiodev
#安装它并收集任何依赖项库-RPATH不需要
sudo mkdir-p$TARG
sudo chown'whoami`。用户$TARG
安装
#收集二进制库###如果添加任何其他模块,请重复此操作##
函数collect_binary_libs{
cd$TARG
查找-name'*.so'| sed's/^/ldd-v/'>elf文件
echo“ldd-v bin/python”>>elf文件
chmod+x文件
/elffiles | sed's/*=>/;s/*/;/:$/d;s/^*/'| sort-u | sed's/*/cp-L&lib/'>lddinfo
#mkdir库
chmod+x lddinfo
/lddinfo
光盘~
}
收集二进制库
#设定路径
光盘~
导出路径=$TARG/bin:$PATH
#安装的安装工具
$WGEThttp://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
chmod+x setuptools-0.6c11-py2.7.0
./setuptools-0.6c11-py2.7.1
#已安装的virtualenv
tar zxvf virtualenv-1.6.1.tar.gz
cd virtualenv-1.6.1
python setup.py安装
光盘~
#创建了一个基本的virtualenv,它应该适用于几乎所有的项目
#我们使它可以重新定位,以防它在文件系统中的位置发生变化。
光盘~
python virtualenv-1.6.1/virtualenv.py/data1/py27base#首先实现它
python virtualenv-1.6.1/virtualenv.py——可重新定位/data1/py27base#然后重新定位
#看看
source~/junk/bin/activate
python——版本
#用有用的模块填充virtualenv
#注意可能存在依赖性问题的二进制生成
导出LD\u运行路径='\$$ORIGIN:\$$ORIGIN/./lib:\$$ORIGIN/./../lib'
简易安装pip
pip安装cython
pip安装lxml
pip安装httpli