maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   compiling python scripts (https://talk.maemo.org/showthread.php?t=22958)

Delphipgmr 2008-08-18 20:54

compiling python scripts
 
is there a way to compile python scripts in maemo?

fatalsaint 2008-08-18 21:01

Re: compiling python scripts
 
Um... You don't 'compile' a python script??

Python is an interpereted language.. not a compiled language.. it simply reads commands form a python script line by line and executes them.. just like Perl, Ruby, Bash, Visual Basic, Batch...

Maybe I'm missing something?

If you install the python tools in maemo, most python scripts should run fine - assuming you have the dependencies required for them..

Thesandlord 2008-08-18 21:08

Re: compiling python scripts
 
Not sure if this is right...

Code:

$ sudo gainroot
# chmod +x name_of_app

This makes it executable. There is no need to compile a python application. It runs from the source code...

Delphipgmr 2008-08-18 21:32

Re: compiling python scripts
 
no, i meant if i ever wanted to have a distribution and no-one to see the source.

pycage 2008-08-19 06:28

Re: compiling python scripts
 
Quote:

Originally Posted by fatalsaint (Post 215037)
Python is an interpereted language.. not a compiled language.. it simply reads commands form a python script line by line and executes them.. just like Perl, Ruby, Bash, Visual Basic, Batch...

This is not 100% correct. Python interprets byte code. The byte code is generated automatically when you run the application and can be found in the .pyc files. If you really feel like shipping without the source code, you can just ship the .pyc files and the application will still run.
You can also tell Python to produce "optimized" and documentation-less byte code with the -OO switch, e.g.
Code:

python -OO myapp.py
So if you run the code once, you have the "compiled" byte code. There's no dedicated compiler, but one can be written with a few lines of Python, if needed. The byte code compiler is available as a Python module for this.

pycage 2008-08-19 06:33

Re: compiling python scripts
 
Btw, Canola2 is mostly closed-source and just ships the byte code, if you need an example (of how to annoy people by not releasing the source code...)

danramos 2008-08-19 08:02

Re: compiling python scripts
 
Quote:

Originally Posted by fatalsaint (Post 215037)
Um... You don't 'compile' a python script??

Python is an interpereted language.. not a compiled language.. it simply reads commands form a python script line by line and executes them.. just like Perl, Ruby, Bash, Visual Basic, Batch...

Maybe I'm missing something?

If you install the python tools in maemo, most python scripts should run fine - assuming you have the dependencies required for them..


Generally, you really have little or no reason to ever compile Perl or Python code.. but you are incorrect.

http://www.faqs.org/docs/perl5int/compiler.html

More specifically, for Python:
http://docs.python.org/lib/compiler.html

This seems interesting, but considering it's resources and architecture requirements, it wouldn't work in this case at all:
http://psyco.sourceforge.net/introduction.html


But I digress and return to the original point--you really shouldn't try to COMPILE Python code. There's little to no advantage at all and there's often a disadvantage to it.

Is there a specific purpose you had in mind that you think requires compiled code to run?

danramos 2008-08-19 08:05

Re: compiling python scripts
 
Quote:

Originally Posted by Delphipgmr (Post 215051)
no, i meant if i ever wanted to have a distribution and no-one to see the source.

Ahha.. you already answered before my post. In this case, yes--compiled code is the way to go. Just remember that there's no guarantee that it couldn't easily be reverse engineered (decompiled) pretty easily.

fatalsaint 2008-08-19 15:54

Re: compiling python scripts
 
So those that say I am incorrect (I hadn't seen the bytecode):

Can you run/execute Python bytecode without python installed?

"Compiled" languages - IE C++ - do no required the end user to actually have C++ installed on the machine to run their application.. that is my determination of a 'compiled' language...

I knew of perl modules that "scrambled" the perl code.. like ACME something or other.. but straight from perl's page:
Quote:

The Perl compiler is not just for compiling Perl code to a standalone executable - in fact, some would argue that it's not at all for compiling Perl into a standalone executable.
Quote:

All the compiler is, essentially, is a way of getting access to the op tree and doing something potentially interesting with it.
That does not look like "compiling" software in any normal sense of the term to me. And if the python "bytecode" still required "python" then all you did was translate something from being human readable to something more native to python itself - but it's still running the script in much the same way.

That is also no different than trying to "encrypt" a file.. a bytecode translator could likely (I would think) be relatively easy written to change from bytecode to english again.

If the python's bytecode could be distributed and used so long as the appropriate libraries were on the destination machine without needing python.. then I'd see it being more of a hybrid between an interpereted and compiled language.

But then I'm not a software developer all day.. I merely do coding as a side-hobby. I also didn't know about Canola.. it seems silly to me why someone would use a scripting language to write a closed source application.. that doesn't make much sense in my mind.

pycage 2008-08-19 17:13

Re: compiling python scripts
 
Maybe you should stop thinking about Python as a "scripting language" just because it's being interpreted. It actually sucks at being a good scripting language. Common scripting languages such as Perl or shell code do that job much better, in my opinion.

Python is a dynamically typed object-oriented interpreted language, so I would rather compare it more with smalltalk or Java rather than with common scripting languages.
Btw, Java programs also need java to be run on a machine. The same goes with .net.

If you really need to compile Python code into an executable which runs without python, you should take a look at "freeze", IIRC.

Delphipgmr 2008-08-19 18:16

Re: compiling python scripts
 
yes i have found freeze too.

as you can tell from my name, i am a programmer (borland delphi is my favorite).

im just interested in learning python, never did it before.. so im just asking these things for future reference, and to see if its worth my time with python, or learn C++ (ive done c++ before, its just been years and on a different platform)

there isnt any particular application in mind.

danramos 2008-08-19 18:30

Re: compiling python scripts
 
My reading tells me that Python uses a virtual machine like Java does.. and it DOES compile its own tokenized instructions the way Java (and Assembly for that matter). So you CAN 'compile' it and if you just have the Python's virtual machine to run the tokenized code, you don't need the entire Python language installed.


All times are GMT. The time now is 22:02.

vBulletin® Version 3.8.8