freeze and ActiveState's WinPython?

Carlos Ribeiro cribeiro at mail.inet.com.br
Sat Feb 15 18:36:33 EST 2003


On Saturday 15 February 2003 17:03, Lance wrote:
> Thanks Jeff... but my understanding is the py2exe will only create a
> Windows executable. I want to create a Linux and Unix executable.

Lance, 

I'll try to present a roadmap for you, as simple as I can. I hope it helps.

First of all, I'm assuming that you want to compile your program as a binary 
for easy distribution, and also to avoid your code from being looked upon or 
modified. In this case, you have to break your problem in two parts: 
compiling your application as a binary, and packaging it for distribution. 
For reasons that will be clear as your read the rest of this post, the second 
problem is *more* important, and I'll talk about it first.

Making a Python executable for Unix isn't as easy (in the general case) as 
doing the same for Windows; first of all, Unix isn't a single platform or 
even a single target processor. Devising a generic packaging scheme for Unix 
is, by definition, hairier than simply running py2exe.

Said that, you should start asking a few questions first, before researching 
on particular solutions:

- What is your target processor architecture? In other words, being compiled 
as generic x86 binary code is good enough for your needs?

- What flavor of Unix do you want to support?

- Complementing the question above, it's important to define what are the 
distributions that you are going to support; for example, Redhat, Debian, 
Mandrake, Suse...

Once you have all these questions asked, then you can start researching for a 
packaging solution that is available on your target system. A good bet is 
that you'll choose RPM, that can be used on several widely used Linux 
distributions such as RedHat and Mandrake, to name a few. APT is also a 
candidate, being available natively for Debian, and also in new releases of 
other distributions such as RedHat.

In the other end of the spectrum, you *may* simply compile your application in 
your computer and then distribute the executable. But this does not solve 
several issues related to the availability of shared libraries. However, if 
you are going to install everything manually, this may not be an issue.

Once you have decided how to package your program, there still a few questions 
that you need to answer before proceeding:

- if you just want to make your system easy to install, you can simply package 
your native Python source files. There is no need to make a binary, unless 
you don't want to include your source files.

- if you need to compile your application, then the decision on how to make it 
also depends on the choce of the target system and platform. 

As far as I know, the 'standard' technique to compile a Python program under 
Unix is to embed Python in a small C program. From your C program, you 
initialize the embedded Python environment and execute your program, passing 
it as a C string. Python modules can be left as .pyc (compiled Python) files, 
but the main program has to be passed to the embedded Python interpreter this 
way. (btw, I don't know how to include all modules within your binary file - 
never needed to do it - but I'm sure it can be done).

Finally, in order to be able to compile your program as I described, you'll 
need to install a lot of tools; Unix itself, lots of source code and include 
files, libraries, C compiler, etc. I'm assuming that you know how to install 
this stuff, but you can research this elsewhere - I'm sure you'll find better 
people to explain it than me.


Carlos Ribeiro
cribeiro at mail.inet.com.br





More information about the Python-list mailing list