PDA

View Full Version : python compiler



rpmp
July 23rd, 2011, 10:26 PM
how do u compile programs in python using ubuntu?

CptPicard
July 23rd, 2011, 10:32 PM
Any particular reason why you'd want to do this?

rpmp
July 23rd, 2011, 10:46 PM
im not even sure if u can compile python programs on linux im asking if u can and with wath?

CptPicard
July 23rd, 2011, 10:58 PM
Well, there is something like psyco, but mostly you just run it through the regular interpreter...

Thewhistlingwind
July 23rd, 2011, 11:29 PM
I think he means to bytecode.

Anyway, I'm pretty sure you want the py compile module.

http://effbot.org/zone/python-compile.htm

Have fun!

TwoEars
July 23rd, 2011, 11:59 PM
how do u compile programs in python using ubuntu?

Depends entirely on what you mean and what you understand. Clarify that, and you'll get your answer ;)

Lux Perpetua
July 24th, 2011, 02:42 AM
how do u compile programs in python using ubuntu?Simple: you don't. You run them with the python interpreter:
$ python my_program.py (9:1 odds the OP just doesn't know that there are such things as "compiled" and "interpreted" languages.)

Dhiraj Thakur(Invincible)
July 24th, 2011, 05:49 AM
Simple: you don't. You run them with the python interpreter:
$ python my_program.py (9:1 odds the OP just doesn't know that there are such things as "compiled" and "interpreted" languages.)
The answer Lua gave is correct.....if you want a standalone executable you should consider pyinstaller or py2exe....

The Cyph3r
July 24th, 2011, 05:54 AM
Try C++ if you want to compile.

nvteighen
July 24th, 2011, 04:04 PM
At least on Debian, PyCentral installs a command called py_compilefiles, which is used for deb packaging using PyCentral. I'm not sure if it's even called by default when building the deb package.

But really, why do you want to do this? It's highly impractical during development and it brings little advantages. Disassembling a Python module is extremely easy... (all you need is a core module, not any arcane tool!).

StephenF
July 24th, 2011, 09:00 PM
The answer Lua gave is correct.....if you want a standalone executable you should consider pyinstaller or py2exe....
And with Ubuntu there is nothing to be gained from a standalone executable.

To compile to bytecode just import your program.


$ python
Python 2.7.1 (r271:86832, Apr 18 2011, 19:52:46)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import myprogram

This generates myprogram.pyc, but really there is no need for such things until you are using some kind of build system for your project. It saves a few milliseconds, that's all.