# Creating Binary Python Executables



## MetalheadGautham (Jan 19, 2009)

There are a handful of python programs I find really useful but they are all in *.py format. Often I need to use them in a distro which has no package for python installed or is barebones. In such cases, is there a way to make binary python executables ? How ?


----------



## Liverpool_fan (Jan 19, 2009)

MetalheadGautham said:


> There are a handful of python programs I find really useful but they are all in *.py format. Often I need to use them in a distro which has no package for python installed or is barebones. In such cases, is there a way to make binary python executables ? How ?



Yes. It is called creating Frozen Binaries. In frozen binaries, they bundle the byte code of your program with the interpreter into a single binary. Keep note you have to account for size of the interpreter in this case. A typical python source .py will cost just few KB will take a few more MBs.
Anyway PyInstaller will do the job.
*pyinstaller.python-hosting.com/

If you wan't to target Microsoft Windows alone, then there's py2exe:
*www.py2exe.org/


----------



## MetalheadGautham (Jan 19, 2009)

Thanks. Does py2exe work for all python files effectively ?

And I also need something for linux. I prefer an official built-in method if there exists one.


----------



## Liverpool_fan (Jan 19, 2009)

MetalheadGautham said:


> Thanks. Does py2exe work for all python files effectively ?
> 
> And I also need something for linux. I prefer an official built-in method if there exists one.



PyInstaller works for Linux, I have not tested it though. But there's no "official built-in" method AFAIK.
In Linux it is rare if one needs a binary eg. your case in which there's no python (which distro it is BTW?)
It is more practical to create a bash script or creating a launcher if python's installed.
Either:

```
chmod +x code.py
```

OR


Create a bash script: (if you want to make things harder, )

```
#!/usr/bin/env bash
python code.py
read -p "Press any key to exit"
```


----------



## Sykora (Jan 19, 2009)

Every self-respecting mainstream linux distribution comes with python, so there's no need for you to worry about whether that will be there.

As far as an installation method is concerned, the general python way of producing an installer is using the python *disutils* module. Check that one out.


----------



## MetalheadGautham (Jan 19, 2009)

I am not talking about mainstream distros. I am talking about certain use and forget live distros.

And yeah, is there something similar for perl ? I want a binary of powerpill so that I can use it in a barebones systemto start installing software.


----------



## MetalheadGautham (Jan 27, 2009)

bump.


----------



## Liverpool_fan (Jan 27, 2009)

I don't have much knowledge of Perl. But a quick google search result in finding perl2exe:
*www.indigostar.com/perl2exe.htm
(they seem to imply it works in Linux as well)

Also: There is perlcc:
*www.perl.com/doc/manual/html/utils/perlcc.html

Hope this helps.


----------



## MetalheadGautham (Jan 27, 2009)

hmm... perlcc is what I am looking for.
Does it attach an interpreter like python or does it create REAL executable code ?

And is there a way to create REAL executable code from Python, like in C++ ?


----------



## Liverpool_fan (Jan 27, 2009)

MetalheadGautham said:


> hmm... perlcc is what I am looking for.
> Does it attach an interpreter like python or does it create REAL executable code ?


I think it attaches an interpreter like Python.



> And is there a way to create REAL executable code from Python, like in C++ ?



NO.

However...There is Shedskin C++ Translator which attempts to translate Python Code to C++.. However it is still at infancy and limits python to being "statically typed" and may not work for all scripts.
If indeed Python could be totally compiled to machine level code, nobody would have used C/C++.


----------

