Sneitzke38
Sneitzke38

Reputation: 437

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

I have already created a 64-bit program for windows using cx freeze on a 64-bit machine. I am using Windows 7 64-bit Home premium. py2exe is not working because as i understand it does not work with python 3.2.2 yet. Is there an option i have to specify in cx freeze to compile in 32-bit instead of 64-bit.

Thanks!

Upvotes: 12

Views: 18157

Answers (3)

bossi
bossi

Reputation: 1673

In addition to the answers already given:

  1. To compile/freeze python code for different architectures (x86/x64), install both, x86 and x64 versions of python, to your system and corresponding variations of all required modules and libraries to your python installations so both installations have the same (required) set of packages installed.
  2. The next step is to check that your global OS environment is configuredcorrectly. The following Windows environment variables need to point to the appropriate installation of Python you want to freeze to, You should know which locations they need to point to:
    • %PATH%
    • %PYTHONHOME%
    • %PYTHONPATH%
  3. Once you've set them up properly, re-open any terminals to make sure you've got the new environment loaded (re-login to your Windows session if necessary to properly refresh your environment) and you are ready to run your cx_freeze and any other python-related build ops to get your final builds for that architecture.
  4. Once done with those builds, re-run the process from step 2. to change your Windows environment to the next python installation and build.

To speed up the environment-change process I either script those steps or use a VM.

Hope this helps.

Upvotes: 4

David Heffernan
David Heffernan

Reputation: 613003

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

Upvotes: 8

Ben
Ben

Reputation: 71495

All the "produce an executable from Python code" methods I know of basically create a file that bundles up the Python interpreter with the Python code you want to execute inside a single file. It is nothing at all like compiling C code to an executable; Python is just about impossible to compile to machine code in any significantly more useful way than just gluing the Python bytecode to the machine code for a Python interpreter.

So that's almost certainly why you can't produce a 32 bit exe from a 64 bit installation of Python; there isn't a 32 bit interpreter to embed in the output file.

Upvotes: 0

Related Questions