如何在64位Ubuntu上安装32位python

我正在使用Ubuntu 10.10( Linux pc07 2.6.35-27-generic #48-Ubuntu SMP Tue Feb 22 20:25:46 UTC 2011 x86_64 GNU/Linux )和默认的python包(Python 2.6.6)。

我想安装python-psyco以提高我的一个脚本的性能,但只有python-psyco-doc可用于64位。 我尝试了一个虚拟机,但虚拟机上的性能提升远远低于“真正”安装的32位Ubuntu。

所以我的问题是:如何在我的64Bit Ubuntu机器上安装带有psyco的32Bit Python?

编辑:我发现这篇文章并做了这个:

  • 从http://python.org/download/下载“Python 2.7.1 bzipped source tarball”
  • 进入解压缩的目录“Python 2.7.1”
  • OPT=-m32 LDFLAGS=-m32 ./configure --prefix=/opt/pym32
  • make

但是我收到了这个错误:

 gcc -pthread -m32 -Xlinker -export-dynamic -o python \ Modules/python.o \ libpython2.7.a -lpthread -ldl -lutil -lm libpython2.7.a(posixmodule.o): In function `posix_tmpnam': /home/moose/Downloads/Python-2.7.1/./Modules/posixmodule.c:7346: warning: the use of `tmpnam_r' is dangerous, better use `mkstemp' libpython2.7.a(posixmodule.o): In function `posix_tempnam': /home/moose/Downloads/Python-2.7.1/./Modules/posixmodule.c:7301: warning: the use of `tempnam' is dangerous, better use `mkstemp' Segmentation fault make: *** [sharedmods] Fehler 139 

编辑2:现在我找到了http://indefinitestudies.org/2010/02/08/how-to-build-32-bit-python-on-ubuntu-9-10-x86_64/ ,看起来这有效:

  • cd Python-2.7.1
  • CC="gcc -m32" LDFLAGS="-L/lib32 -L/usr/lib32 \ -L pwd /lib32 -Wl,-rpath,/lib32 -Wl,-rpath,/usr/lib32" \ ./configure --prefix=/opt/pym32
  • make
  • sudo make install

但安装psyco不起作用:

  • 下载最新快照: http : //psyco.sourceforge.net/download.html
  • 解压缩并进入文件夹
  • python setup.py安装

出现此错误:

 PROCESSOR = 'ivm' running install running build running build_py running build_ext building 'psyco._psyco' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DALL_STATIC=1 -Ic/ivm -I/usr/include/python2.6 -cc/psyco.c -o build/temp.linux-x86_64-2.6/c/psyco.o In file included from c/psyco.c:1: c/psyco.h:9: fatal error: Python.h: Datei oder Verzeichnis nicht gefunden compilation terminated. error: command 'gcc' failed with exit status 1 

安装包python-dev解决了这个问题,但我仍然无法使用psyco。 现在我已经安装了32位Ubuntu系统。

要在64位Ubuntu系统上运行32位应用程序,您将需要ia32-libs 。 从终端validation您是否使用此function

 dpkg -l ia32-libs 

如果您已安装它,输出应如下所示:

 ii ia32-libs ... 

如果它看起来像un ia32-libs ,则需要使用以下命令安装它:

 sudo apt-get install ia32-libs 

我终于通过安装一个32位的schroot环境来实现这个目的。 按照此处的说明操作: https : //help.ubuntu.com/community/DebootstrapChroot

我为schroot使用了以下配置文件( /etc/schroot/chroot.d/natty32.conf ):

 [natty32] description=Ubuntu 11 for i386 directory=/srv/chroot/natty32 personality=linux32 root-users=myloginname type=directory users=myloginname 

安装后,启动schroot会话:

 schroot -c natty32 -u root 

然后使用apt-get安装python2.6,使用它安装pip( http://guide.python-distribute.org/installation.html ),然后pip install psyco,numpy,&c。