How to Build 32Bit Python 2.6 on 64Bit Linux

How to build 32bit python 2.6 on 64bit Linux?

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.

Create 32-bit exe's from python code on 64-bit machine

To produce 32 bit executables you need to install 32-bit versions of Python and cx_freeze.

Which command to use for checking whether python is 64bit or 32bit

For Python 2.6 and above, you can use sys.maxsize as documented here:

import sys
is_64bits = sys.maxsize > 2**32

UPDATE: I notice that I didn't really answer the question posed. While the above test does accurately tell you whether the interpreter is running in a 32-bit or a 64-bit architecture, it doesn't and can't answer the question of what is the complete set of architectures that this interpreter was built for and could run in. As was noted in the question, this is important for example with Mac OS X universal executables where one executable file may contain code for multiple architectures. One way to answer that question is to use the operating system file command. On most systems it will report the supported architectures of an executable file. Here's how to do it in one line from a shell command line on most systems:

file -L $(python -c 'import sys; print(sys.executable)')

Using the default system Python on OS X 10.6, the output is:

/usr/bin/python: Mach-O universal binary with 3 architectures
/usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386): Mach-O executable i386
/usr/bin/python (for architecture ppc7400): Mach-O executable ppc

On one Linux system:

/usr/bin/python: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, stripped

BTW, here's an example of why platform is not reliable for this purpose. Again using the system Python on OS X 10.6:

$ arch -x86_64 /usr/bin/python2.6 -c 'import sys,platform; print platform.architecture()[0], sys.maxsize > 2**32'
64bit True
$ arch -i386 /usr/bin/python2.6 -c 'import sys,platform; print platform.architecture()[0], sys.maxsize > 2**32'
64bit False

Using multiple Python engines (32Bit/64bit and 2.7/3.5)

Make sure to set the right environmental variables (https://github.com/conda/conda/issues/1744)

Create a new environment for 32bit Python 2.7:

set CONDA_FORCE_32BIT=1
conda create -n py27_32 python=2.7

Activate it:

set CONDA_FORCE_32BIT=1
activate py27_32

Deactivate it:

deactivate py27_32

Create one for 64 bit Python 3.5:

set CONDA_FORCE_32BIT=
conda create -n py35_64 python=3.5

Activate it:

set CONDA_FORCE_32BIT=
activate py35_64

The best would be to write the activation commands in a batch file so that you have to type only one command and cannot forget to set the right 32/64 bit flag.

UPDATE

You don't need to install a full Anaconda distribution for this. Miniconda is enough:

These Miniconda installers contain the conda package manager and Python. Once Miniconda is installed, you can use the conda command to install any other packages and create environments, etc. ...

There are two variants of the installer: Miniconda is Python 2 based and Miniconda3 is Python 3 based. Note that the choice of which Miniconda is installed only affects the root environment. Regardless of which version of Miniconda you install, you can still install both Python 2.x and Python 3.x environments.

I would recommend you to use Miniconda3 64-bit as your root environment.

You can always install a full Anaconda later with:

conda install anaconda

Note that it might downgrade some of your previously install packages in your active environment.

Linking with 32bit libraries under linux 64bit

Well, you can't mix and match 32-bit and 64-bit code. If you compile all your code using -m32 (to make it build as 32-bit), you may be able to get your application to link if you have 32-bit versions of all your libraries available.



Related Topics



Leave a reply



Submit