Make Your Own Python Compiler

Linux tutorials and code.
5 posts Page 1 of 1
Contributors
User avatar
mikethedj4
VIP - Site Partner
VIP - Site Partner
Posts: 2592
Joined: Thu Mar 25, 2010 4:36 am

Make Your Own Python Compiler
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
Last edited by mikethedj4 on Mon Oct 11, 2010 4:26 pm, edited 1 time in total.
User avatar
DarkyKnife
Top Poster
Top Poster
Posts: 109
Joined: Thu Apr 29, 2010 4:59 pm

So that is in Linux?
Visit my Youtube chanel
User avatar
mikethedj4
VIP - Site Partner
VIP - Site Partner
Posts: 2592
Joined: Thu Mar 25, 2010 4:36 am

If you have python installed on windows or a mac this will work as a compiler for all platforms.
User avatar
DarkyKnife
Top Poster
Top Poster
Posts: 109
Joined: Thu Apr 29, 2010 4:59 pm

Cool it works, thanks!
Visit my Youtube chanel
User avatar
mikethedj4
VIP - Site Partner
VIP - Site Partner
Posts: 2592
Joined: Thu Mar 25, 2010 4:36 am

No problem
5 posts Page 1 of 1
Return to “Programming”