PDA

View Full Version : Python: how can I create a bin file of a python program?



holihue
October 17th, 2007, 03:41 PM
Is there a way to create a bin file of a Python program?

I want a bin file like when you compile a program from source.



Thanks

Foxmike
October 18th, 2007, 06:50 PM
Since python is a scripting language, it doesn't produces binaries. It is compiled at run-time.

Tho, you still can get some .pyc files, as I understood those are semi-compiled files. Unless you want to close the sourcre from being seen/edited, I don't see why someone would do such a thing, tho.

holihue
October 19th, 2007, 03:45 PM
Since python is a scripting language, it doesn't produces binaries. It is compiled at run-time.

Tho, you still can get some .pyc files, as I understood those are semi-compiled files. Unless you want to close the sourcre from being seen/edited, I don't see why someone would do such a thing, tho.

OK, Thank you.:)

pmasiar
October 19th, 2007, 04:35 PM
Binary for which platform? There are compilers, which can compile .pyc further to real binaries (like psyco), but not many people bothers with it. Why you need it?

BTW .pyc files are compiled to intermediate code, so they can be executed rather efficiently. They are not interpreted at the runtime like classic "scripting" language do, whatever "scripting" means. :-)

holihue
October 21st, 2007, 10:56 AM
Why you need it?


I have a project on sf.net, and I wanted more versions of it...

pmasiar
October 22nd, 2007, 09:08 PM
I wanted more versions of it...

this is not your business goal. What you want to accomplish?

Foxmike
October 24th, 2007, 03:31 AM
Binary for which platform? There are compilers, which can compile .pyc further to real binaries (like psyco), but not many people bothers with it. Why you need it?

BTW .pyc files are compiled to intermediate code, so they can be executed rather efficiently. They are not interpreted at the runtime like classic "scripting" language do, whatever "scripting" means. :-)
Thanks for the precision!:)

evymetal
October 29th, 2007, 09:53 AM
There are python "compilers" out there that wrap up all your modules and the interpreter into an executable. I've found this useful for distributing software to Windows users, although you can also get "compilers" for linux,BSD,OSX etc.

One thing you do need to be aware of if you are thinking of distributing .pyc files is that the .pyc file format is interpreter-dependent, so if you have python 2.4 and you give your pyc files to someone with python 2.1 they probably won't run.

This can also be a problem for code, Python is a fairly new language and as such it's changing constantly. The only way to ensure your app will continue to run on later versions of python is to package it as above so it is run on the correct interpreter. Of course, most apps should continue to run fine (unless they do decide to remove lamda: and map.)


p.s. Psyco isn't a packager, but a JIT compiler that kind of reduces the cost of python's dynamic typing.

Amaranth
October 31st, 2007, 10:55 PM
Python is actually 16 years old.

master_kernel
November 1st, 2007, 08:36 PM
There is a setup.py script out there... I use it for KernelCheck.

calande
November 4th, 2007, 06:12 PM
On Windows there is py2exe (http://www.py2exe.org), there's gotta an equivalent for Unix...

RAOF
November 5th, 2007, 03:33 AM
On Windows there is py2exe (http://www.py2exe.org), there's gotta an equivalent for Unix...

Probably not. Unlike windows, we have an actual software manager, so applications tend not to ship their dependencies (which is precisely what py2exe is doing).

The real question is "why do you want it" :).

evymetal
November 5th, 2007, 11:47 AM
There is a version for *nix - I think pyinstall may do it. If not have a search.

There is one major bonus of packaging a python app like this - you know what version of the interpreter modules you are going to be running on.

All that the "compilers" do is wrap your code and an interpreter in a single package, load your code into RAM and run it through the standard compiler, so don't expect any speed gains (in fact, it'll probably take slightly longer to load). You can use psyco too, and package that with it.


Re: Python is 16 years old

Wow, time flies.