在Ubuntu中编译Python 2.6.6并需要外部包wxPython,setuptools等

前端之家收集整理的这篇文章主要介绍了在Ubuntu中编译Python 2.6.6并需要外部包wxPython,setuptools等前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用google-perf工具(tcmalloc)库编译了Python 2.6.6,以消除我使用默认2.6.5时遇到的一些内存问题.在获得2.6.6之后它似乎无法工作,因为我认为在Ubuntu中存在默认2.6.5安装问题.从wxPython和setuptools这样的软件通道安装的二进制文件是否都不能正常使用2.6.6.这些需要重新编译吗?任何其他建议,以使其顺利运作.我可以在不更改路径的情况下将2.6.5设置为默认值吗?该路径首先在usr / local / bin中查找.
一个好的一般经验法则是永远不要使用默认系统安装的Python来进行除杂项系统管理脚本之外的任何软件开发.这适用于所有UNIX,包括Linux和OS / X.

相反,使用您需要的库(Python和C)构建一个您控制的优秀Python发行版,并将此tarball安装在非系统目录中,例如/ opt / devpy或/ data / package / python或/ home /蟒蛇.为什么2.7.2可用时为什么要乱用2.6?

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

(实际上,经过一些调整之后我认为这可能会像脚本一样运行,但是我会推荐类似./pybuild.sh> pylog 2>& 1这样你就可以梳理输出并验证所有内容是否正常.

这是建立在Ubuntu 64位上的

  1. #!/bin/bash
  2.  
  3. shopt -s compat40
  4.  
  5. export WGET=echo
  6. #uncomment the following if you are running for the first time
  7. export WGET=wget
  8.  
  9. sudo apt-get -y install build-essential
  10. sudo apt-get -y install zlib1g-dev libxml2-dev libxslt1-dev libssl-dev libncurses5-dev
  11. sudo apt-get -y install libreadline6-dev autotools-dev autoconf automake libtool
  12. sudo apt-get -y install libsvn-dev mercurial subversion git-core
  13. sudo apt-get -y install libbz2-dev libgdbm-dev sqlite3 libsqlite3-dev
  14. sudo apt-get -y install curl libcurl4-gnutls-dev
  15. sudo apt-get -y install libevent-dev libev-dev librrd4 rrdtool
  16. sudo apt-get -y install uuid-dev libdb4.8-dev memcached libmemcached-dev
  17. sudo apt-get -y install libMysqLclient-dev libexpat1-dev
  18.  
  19. cd ~
  20. $WGET 'http://code.google.com/p/google-perftools/downloads/detail?name=google-perftools-1.7.tar.gz'
  21. $WGET http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
  22. tar zxvf Python-2.7.2.tgz
  23. cd Python-2.7.2
  24.  
  25. #following is needed if you have an old version of Mercurial installed
  26. #export HAS_HG=not-found
  27.  
  28. # To provide a uniform build environment
  29. unset PYTHONPATH PYTHONSTARTUP PYTHONHOME PYTHONCASEOK PYTHONIOENCODING
  30. unset LD_RUN_PATH LD_LIBRARY_PATH LD_DEBUG LD_TRACE_LOADED_OBJECTS
  31. unset LD_PRELOAD SHLIB_PATH LD_BIND_NOW LD_VERBOSE
  32.  
  33. ## figure out whether this is a 32 bit or 64 bit system
  34. m=`uname -m`
  35. if [[ $m =~ .*64 ]]; then
  36. export CC="gcc -m64"
  37. NBITS=64
  38. elif [[ $m =~ .*86 ]]; then
  39. export CC="gcc -m32"
  40. NBITS=32
  41. else # we are confused so bail out
  42. echo $m
  43. exit 1
  44. fi
  45.  
  46. # some stuff related to distro independent build
  47. # extra_link_args = ['-Wl,-R/data1/python27/lib']
  48. #--enable-shared and a relative
  49. # RPATH[0] (eg LD_RUN_PATH='${ORIGIN}/../lib')
  50.  
  51. export TARG=/data1/packages/python272
  52. export TCMALLOC_SKIP_SBRK=true
  53. #export CFLAGS='-ltcmalloc' # Google's fast malloc
  54. export COMMONLDFLAGS='-Wl,-rpath,\$$ORIGIN/../lib -Wl,-rpath-link,\$$ORIGIN:\$$ORIGIN/../lib:\$$ORIGIN/../../lib -Wl,-z,origin -Wl,--enable-new-dtags'
  55. # -Wl,-dynamic-linker,$TARG/lib/ld-linux-x86-64.so.2
  56. export LDFLAGS=$COMMONLDFLAGS
  57. ./configure --prefix=$TARG --with-dbmliborder=bdb:gdbm --enable-shared --enable-ipv6
  58.  
  59. # if you have ia32-libs installed on a 64-bit system
  60. #export COMMONLDFLAGS="-L/lib32 -L/usr/lib32 -L`pwd`/lib32 -Wl,$TARG/lib32 -Wl,$TARG/usr/lib32"
  61.  
  62. make
  63. # ignore failure to build the following since they are obsolete or deprecated
  64. # _tkinter bsddb185 dl imageop sunaudiodev
  65.  
  66. #install it and collect any dependency libraries - not needed with RPATH
  67. sudo mkdir -p $TARG
  68. sudo chown `whoami`.users $TARG
  69. make install
  70.  
  71. # collect binary libraries ##REDO THIS IF YOU ADD ANY ADDITIONAL MODULES##
  72. function collect_binary_libs {
  73. cd $TARG
  74. find . -name '*.so' | sed 's/^/ldd -v /' >elffiles
  75. echo "ldd -v bin/python" >>elffiles
  76. chmod +x elffiles
  77. ./elffiles | sed 's/.*=> //;s/ .*//;/:$/d;s/^ *//' | sort -u | sed 's/.*/cp -L & lib/' >lddinfo
  78. # mkdir lib
  79. chmod +x lddinfo
  80. ./lddinfo
  81. cd ~
  82. }
  83. collect_binary_libs
  84.  
  85. #set the path
  86. cd ~
  87. export PATH=$TARG/bin:$PATH
  88.  
  89. #installed setuptools
  90. $WGET http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
  91. chmod +x setuptools-0.6c11-py2.7.egg
  92. ./setuptools-0.6c11-py2.7.egg
  93.  
  94. #installed virtualenv
  95. tar zxvf virtualenv-1.6.1.tar.gz
  96. cd virtualenv-1.6.1
  97. python setup.py install
  98. cd ~
  99.  
  100. # created a base virtualenv that should work for almost all projects
  101. # we make it relocatable in case its location in the filesystem changes.
  102. cd ~
  103. python virtualenv-1.6.1/virtualenv.py /data1/py27base # first make it
  104. python virtualenv-1.6.1/virtualenv.py --relocatable /data1/py27base #then relocatabilize
  105.  
  106. # check it out
  107. source ~/junk/bin/activate
  108. python --version
  109.  
  110. # fill the virtualenv with useful modules
  111. # watch out for binary builds that may have dependency problems
  112.  
  113. export LD_RUN_PATH='\$$ORIGIN:\$$ORIGIN/../lib:\$$ORIGIN/../../lib'
  114. easy_install pip
  115. pip install cython
  116. pip install lxml
  117. pip install httplib2
  118. pip install python-memcached
  119. pip install amqplib
  120. pip install kombu
  121. pip install carrot
  122. pip install py_eventsocket
  123. pip install haigha
  124.  
  125. # extra escaping of $signs
  126. export LDFLAGS='-Wl,\$\$$ORIGIN/../lib:\$\$$ORIGIN/../../lib -Wl,\$\$$ORIGIN/../lib -Wl,--enable-new-dtags'
  127. # even more complex to build this one since we need some autotools and
  128. # have to pull source from a repository
  129. mkdir rabbitc
  130. cd rabbitc
  131. hg clone http://hg.rabbitmq.com/rabbitmq-codegen/
  132. hg clone http://hg.rabbitmq.com/rabbitmq-c/
  133. cd rabbitmq-c
  134. autoreconf -i
  135. make clean
  136. ./configure --prefix=/usr
  137. make
  138. sudo make install
  139. cd ~
  140.  
  141. # for zeromq we get the latest source of the library
  142. $WGET http://download.zeromq.org/zeromq-2.1.7.tar.gz
  143. tar zxvf zeromq-2.1.7.tar.gz
  144. cd zeromq-2.1.7
  145. make clean
  146. ./configure --prefix=/usr
  147. make
  148. sudo make install
  149. cd ~
  150. # need less escaping of $signs
  151. export LDFLAGS='-Wl,\$ORIGIN/../lib:\$ORIGIN/../../lib -Wl,\$ORIGIN/../lib -Wl,--enable-new-dtags'
  152. pip install pyzmq
  153. pip install pylibrabbitmq # need to build C library and install first
  154. pip install pylibmc
  155. pip install pycurl
  156. export LDFLAGS=$COMMONLDFLAGS
  157.  
  158.  
  159. pip install cherrypy
  160. pip install pyopenssl # might need some ldflags on this one?
  161. pip install diesel
  162. pip install eventlet
  163. pip install fapws3
  164. pip install gevent
  165. pip install boto
  166. pip install jinja2
  167. pip install mako
  168. pip install paste
  169. pip install twisted
  170. pip install flup
  171. pip install pika
  172. pip install pyMysqL
  173. # pip install py-rrdtool # not on 64 bit???
  174. pip install PyRRD
  175. pip install tornado
  176. pip install redis
  177.  
  178. # for tokyocabinet we need the latest source of the library
  179. $WGET http://fallabs.com/tokyocabinet/tokyocabinet-1.4.47.tar.gz
  180. tar zxvf tokyocabinet-1.4.47.tar.gz
  181. cd tokyocabinet-1.4.47
  182. make clean
  183. ./configure --prefix=/usr --enable-devel
  184. make
  185. sudo make install
  186. cd ..
  187. $WGET http://fallabs.com/tokyotyrant/tokyotyrant-1.1.41.tar.gz
  188. tar zxvf tokyotyrant-1.1.41.tar.gz
  189. cd tokyotyrant-1.1.41
  190. make clean
  191. ./configure --prefix=/usr --enable-devel
  192. make
  193. sudo make install
  194. cd ..
  195. pip install tokyo-python
  196. pip install solrpy
  197. pip install pysolr
  198. pip install sunburnt
  199. pip install txamqp
  200. pip install littlechef
  201. pip install PyChef
  202. pip install pyvb
  203. pip install bottle
  204. pip install werkzeug
  205. pip install BeautifulSoup
  206. pip install XSLTools
  207. pip install numpy
  208. pip install coverage
  209. pip install pylint
  210. # pip install PyChecker ???
  211. pip install pycallgraph
  212. pip install mkcode
  213. pip install pydot
  214. pip install sqlalchemy
  215. pip install buzhug
  216. pip install flask
  217. pip install restez
  218. pip install pytz
  219. pip install mcdict
  220. # need less escaping of $signs
  221.  
  222. pip install py-interface
  223. # pip install paramiko # pulled in by another module
  224. pip install pexpect
  225.  
  226. # SVN interface
  227. $WGET http://pysvn.barrys-emacs.org/source_kits/pysvn-1.7.5.tar.gz
  228. tar zxvf pysvn-1.7.5.tar.gz
  229. cd pysvn-1.7.5/Source
  230. python setup.py backport
  231. python setup.py configure
  232. make
  233. cd ../Tests
  234. make
  235. cd ../Sources
  236. mkdir -p $TARG/lib/python2.7/site-packages/pysvn
  237. cp pysvn/__init__.py $TARG/lib/python2.7/site-packages/pysvn
  238. cp pysvn/_pysvn_2_7.so $TARG/lib/python2.7/site-packages/pysvn
  239. cd ~
  240.  
  241. # pip install protobuf #we have to do this the hard way
  242. $WGET http://protobuf.googlecode.com/files/protobuf-2.4.1.zip
  243. unzip protobuf-2.4.1.zip
  244. cd protobuf-2.4.1
  245. make clean
  246. ./configure --prefix=/usr
  247. make
  248. sudo make install
  249. cd python
  250. python setup.py install
  251. cd ~
  252.  
  253. pip install riak
  254. pip install ptrace
  255. pip install html5lib
  256. pip install metrics
  257.  
  258. #redo the "install binary libraries" step
  259. collect_binary_libs
  260.  
  261. # link binaries in the lib directory to avoid search path errors and also
  262. # to reduce the number of false starts to find the library
  263. for i in `ls $TARG/lib/python2.7/lib-dynload/*.so`
  264. do
  265. ln -f $i $TARG/lib/`basename $i`
  266. done
  267. # for the same reason link the whole lib directory to some other places in the tree
  268. ln -s ../.. $TARG/lib/python2.7/site-packages/lib
  269.  
  270. # bundle it up and save it for packaging
  271. cd /
  272. tar cvf - .$TARG |gzip >~/py272-$NBITS.tar.gz
  273. cd ~
  274.  
  275. # after untarring on another machine,we have a program call imports.py which imports
  276. # every library as a quick check that it works. For a more positive check,run it like this
  277. # strace -e trace=stat,fstat,open python imports.py >strace.txt 2>&1
  278. # grep -v ' = -1' strace.txt |grep 'open(' >opens.txt
  279. # sed <opens.txt 's/^open("//;s/".*//' |sort -u |grep -v 'dynload' |grep '\.so' >straced.txt
  280. # ls -1d /data1/packages/python272/lib/* |sort -u >lib.txt
  281. # then examine the strace output to see how many places it searches before finding it.
  282. # a successful library load will be a call to open that doesn't end with ' = -1'
  283. # If it takes too many tries to find a particular library,then another symbolic link may
  284. # be a good idea

猜你在找的Ubuntu相关文章