How to build 32bit python 2.6 on 64bit Linux?
Asked Answered
Y

2

9

I'm stuck for a full afternoon now trying to get python to build in 32bit mode. I run a 64bit Linux machine with openSUSE 11.3, I have the necessary -devel and -32bit packages installed to build applications in 32bit mode.

The problem with the python build seems to be not in the make run itself, but in the afterwards run of setup.py, invoked by make.

I found the following instructions for Ubuntu Linux: h**p://indefinitestudies.org/2010/02/08/how-to-build-32-bit-python-on-ubuntu-9-10-x86_64/

When I do as described, I get the following output:

http://pastebin.com/eP8WJ8V4

But I have the -32bit packages of libreadline, libopenssl, etc.pp. installed, but of course, they reside under /lib and /usr/lib and not /lib64 and /usr/lib64.

When I start the python binary that results from this build, i get:

./python
Python 2.6.6 (r266:84292, Oct  5 2010, 21:22:06) 
[GCC 4.5.0 20100604 [gcc-4_5-branch revision 160292]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
  File "/etc/pythonstart", line 7, in <module>
    import readline
ImportError: No module named readline

So how to get setup.py to observe the LDFLAGS=-L/lib command??

Any help is greatly appreciated.

Regards, Philipp

Y answered 5/10, 2010 at 19:44 Comment(7)
It may be overkill, but one way to do it is to set up a 32-bit chroot jail and compile it there. It at least guarantees that you won't mix 32 and 64 bit libraries when compiling.Pharmaceutics
this is definitely overkill. Am I the only person in the world to want a 32bit Linux build of python??? I'm googling for hours now and only find instructions for Mac. Apart from the blogpost mentioned above, nobody has instruction for Linux!Y
You're not the only one. I use mine because of IDA Pro python bindings are 32 bits and I don't want a full jail ... I just did it using the link you pointer above and it worked mostly fine for me. Only _bsddb and _tkinter modules didn't build. The former because it tried to link db-4.7 (which is my 64bits version) instead of db-4.8 which is my 32 bits version. The latter because I don't have any tk 32 bits.Triangle
Another reason to do this is if you are creating a redistributable binary of your Python program using something like PyInstaller (so that users can run it without having to mess with pip, or have the right version of Python installed, or even have any Python installed.) The executable PyInstaller produces will be 64 bit if your Python is 64 bit, meaning 32 bit users cannot run it.Harper
Relevant: askubuntu.com/a/74145/173666Inexperience
Relevant: https://mcmap.net/q/939319/-create-32-bit-exe-39-s-from-python-code-on-64-bit-machine/1959808Inexperience
Relevant: https://mcmap.net/q/1020160/-tidying-up-the-cython-build-flags-used-by-gccInexperience
W
11

You'll need to pass the appropriate flags to gcc and ld to tell the compiler to compile and produce 32bit binaries.

Use --build and --host.

./configure --help
System types:
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]

You need to use ./configure --build=x86_64-pc-linux-gnu --host=i686-pc-linux-gnu to compile for 32-bit Linux in a 64-bit Linux system.

Note: You still need to add the other ./configure options.

Wendolynwendt answered 17/11, 2010 at 3:44 Comment(4)
"configure: error: readelf for the host is required for cross builds". Running "locate '*-readelf'" only gives "/usr/bin/x86_64-linux-gnu-readelf". I presume I have to find & install a package that will provide "i686-linux-gnu-readelf" ?Harper
@JonathanHartley If you don't have the appropriate build tools (and probably a cross compiler) it won't work; no :)Wendolynwendt
Relevant: unix.stackexchange.com/a/352784/43390Inexperience
Somewhat relevant for cross-compiling using the MacPorts gcc (which is different than the gcc of macOS): https://mcmap.net/q/1020161/-macports-osx-10-9-2-is-m32-compile-possibleInexperience
T
4

Regarding why, since Kirk (and probably others) wonder, here is an example: I have a Python app with large dicts of dicts containing light-weight objects. This consumes almost twice as much RAM on 64bit as on 32bit simply due to the pointers. I need to run a few instances of 2GB (32bit) each and the extra RAM quickly adds up. For FreeBSD, a detailed recipe for 32bit-on-64bit jail is here http://www.gundersen.net/32bit-jail-on-64bit-freebsd/

Tollmann answered 8/9, 2012 at 18:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.