Reply
Thread Tools
Posts: 91 | Thanked: 10 times | Joined on May 2007
#1
is there a way to compile python scripts in maemo?
 
Posts: 3,428 | Thanked: 2,856 times | Joined on Jul 2008
#2
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..
__________________
If I've helped you or you use any of my packages feel free to help me out.
-----------------------------------------------------------------------------------
Maintaining:
pyRadio - Pandora Radio on your N900, N810 or N800!
 
Posts: 1,213 | Thanked: 356 times | Joined on Jan 2008 @ California and Virginia
#3
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...
 
Posts: 91 | Thanked: 10 times | Joined on May 2007
#4
no, i meant if i ever wanted to have a distribution and no-one to see the source.
 
pycage's Avatar
Posts: 3,404 | Thanked: 4,474 times | Joined on Oct 2005 @ Germany
#5
Originally Posted by fatalsaint View Post
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.
 

The Following 2 Users Say Thank You to pycage For This Useful Post:
pycage's Avatar
Posts: 3,404 | Thanked: 4,474 times | Joined on Oct 2005 @ Germany
#6
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's Avatar
Posts: 4,672 | Thanked: 5,455 times | Joined on Jul 2008 @ Springfield, MA, USA
#7
Originally Posted by fatalsaint View Post
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's Avatar
Posts: 4,672 | Thanked: 5,455 times | Joined on Jul 2008 @ Springfield, MA, USA
#8
Originally Posted by Delphipgmr View Post
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.
 
Posts: 3,428 | Thanked: 2,856 times | Joined on Jul 2008
#9
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:
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.
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.
__________________
If I've helped you or you use any of my packages feel free to help me out.
-----------------------------------------------------------------------------------
Maintaining:
pyRadio - Pandora Radio on your N900, N810 or N800!

Last edited by fatalsaint; 2008-08-19 at 15:57.
 
pycage's Avatar
Posts: 3,404 | Thanked: 4,474 times | Joined on Oct 2005 @ Germany
#10
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.
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 09:26.