Page 1 of 1

Make Your Own Python Compiler

Posted: Mon Oct 11, 2010 12:56 pm
by mikethedj4
One thing that's great about Python is that it allows us to compile it into a bytecode (.pyc)

First open up your terminal and navigate into the directory in which your program's file(s) are, for example my files are in a folder called ScreenScare on my desktop, so I would put down the following terminal command to access that directory (NOTE: The terminal is case sensitive).
Code: Select all
cd Desktop/ScreenScare
Now I would type these terminal commands in order.
Code: Select all
python
import compiler
compiler.compileFile("appname.py")
exit()
NOTE: You can save the code below into a compiler.py file to compile your applications, but don't forget to change the appname.
Code: Select all
import compiler
compiler.compileFile("appname.py")
exit()
After you've compiled your program now it's time to make the .pyc file executable by putting down the following terminal command.
Code: Select all
sudo chmod +x appname.pyc
and now it's time to run the program with this terminal command.
Code: Select all
./helloworld.pyc

Re: Make Your Own Python Compiler

Posted: Mon Oct 11, 2010 3:45 pm
by DarkyKnife
So that is in Linux?

Re: Make Your Own Python Compiler

Posted: Mon Oct 11, 2010 4:23 pm
by mikethedj4
If you have python installed on windows or a mac this will work as a compiler for all platforms.

Re: Make Your Own Python Compiler

Posted: Mon Oct 11, 2010 4:33 pm
by DarkyKnife
Cool it works, thanks!

Re: Make Your Own Python Compiler

Posted: Mon Oct 11, 2010 4:40 pm
by mikethedj4
No problem