chevron_left chevron_right
Login Register invert_colors photo_library


Stay updated and chat with others! - Join the Discord!
Thread Rating:
  • 0 Vote(s) - 0 Average


Compiling Your Python Project filter_list
Author
Message
Compiling Your Python Project #1
Hello [username]!
Python Version used is 3.3
I'll be showing you how to compile your python project using python's built-in module called "py_compile"

1) So first of all open your Python IDE and then type:
Code:
import py_compile

Now you should know the proper path to where your .py (project file) is present.

2) Next type in your Python IDE:
Code:
py_compile.compile('Path_to_your_project.py')

3) Go to your project folder and you'll have your compiled Python File in the "py_cache" folder.
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

RE: Compiling Your Python Project #2
Why do we want to compile it ?
And by compiling, which format do the .py turns into?

Reply

RE: Compiling Your Python Project #3
(06-23-2013, 04:49 AM)zero-uplink Wrote: Why do we want to compile it ?
And by compiling, which format do the .py turns into?

Why Compile It? Well that is a silly question to ask In my opinion because as you work is present in a compiled for you'll be able to execute it directly instead of running it from the python command in command line. After compiling, the format becomes .pyc
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

RE: Compiling Your Python Project #4
Hey Ex094 I think this short thread should be Prefixed with tutorial tag.
[Image: OilyCostlyEwe.gif]

Reply

RE: Compiling Your Python Project #5
(06-23-2013, 04:56 AM)Ex094 Wrote:
(06-23-2013, 04:49 AM)zero-uplink Wrote: Why do we want to compile it ?
And by compiling, which format do the .py turns into?

Why Compile It? Well that is a silly question to ask In my opinion because as you work is present in a compiled for you'll be able to execute it directly instead of running it from the python command in command line. After compiling, the format becomes .pyc

I don't think that's a silly question. After all you are making tutorials for beginners. Someone who doesn't know how to compile most certainly doesn't know why to compile.
So answering that question in your tutorial would be an improvement.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: Compiling Your Python Project #6
(06-23-2013, 08:05 AM)Deque Wrote:
(06-23-2013, 04:56 AM)Ex094 Wrote:
(06-23-2013, 04:49 AM)zero-uplink Wrote: Why do we want to compile it ?
And by compiling, which format do the .py turns into?

Why Compile It? Well that is a silly question to ask In my opinion because as you work is present in a compiled for you'll be able to execute it directly instead of running it from the python command in command line. After compiling, the format becomes .pyc

I don't think that's a silly question. After all you are making tutorials for beginners. Someone who doesn't know how to compile most certainly doesn't know why to compile.
So answering that question in your tutorial would be an improvement.

Agreed! He asked that question in such a way which made me thing he knows about it
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

RE: Compiling Your Python Project #7
(06-23-2013, 08:08 AM)Ex094 Wrote:
(06-23-2013, 08:05 AM)Deque Wrote:
(06-23-2013, 04:56 AM)Ex094 Wrote:
(06-23-2013, 04:49 AM)zero-uplink Wrote: Why do we want to compile it ?
And by compiling, which format do the .py turns into?

Why Compile It? Well that is a silly question to ask In my opinion because as you work is present in a compiled for you'll be able to execute it directly instead of running it from the python command in command line. After compiling, the format becomes .pyc

I don't think that's a silly question. After all you are making tutorials for beginners. Someone who doesn't know how to compile most certainly doesn't know why to compile.
So answering that question in your tutorial would be an improvement.

Agreed! He asked that question in such a way which made me thing he knows about it

My Apologies
My English was not really good.
I just don't know why to compile.
The only thing I know about the term "Compile" in python is, making exe out of .py

I have another question.
When we import a module/library for the first time, python do compile it into .pyc right?
But why not the script that imported the module or library?
It seems to me that python only compile something that is being imported. Not the module or script which imported it.

May be a silly question too. But I really don't know.

Reply

RE: Compiling Your Python Project #8
(06-23-2013, 10:00 AM)zero-uplink Wrote:
(06-23-2013, 08:08 AM)Ex094 Wrote:
(06-23-2013, 08:05 AM)Deque Wrote:
(06-23-2013, 04:56 AM)Ex094 Wrote:
(06-23-2013, 04:49 AM)zero-uplink Wrote: Why do we want to compile it ?
And by compiling, which format do the .py turns into?

Why Compile It? Well that is a silly question to ask In my opinion because as you work is present in a compiled for you'll be able to execute it directly instead of running it from the python command in command line. After compiling, the format becomes .pyc

I don't think that's a silly question. After all you are making tutorials for beginners. Someone who doesn't know how to compile most certainly doesn't know why to compile.
So answering that question in your tutorial would be an improvement.

Agreed! He asked that question in such a way which made me thing he knows about it

My Apologies
My English was not really good.
I just don't know why to compile.
The only thing I know about the term "Compile" in python is, making exe out of .py

I have another question.
When we import a module/library for the first time, python do compile it into .pyc right?
But why not the script that imported the module or library?
It seems to me that python only compile something that is being imported. Not the module or script which imported it.

May be a silly question too. But I really don't know.

I should be the one to apologize! Well in python the .pyc is called Python Compiled Code so no need to mix it up with .exe

There's another module called "compileall" which compiles all the module in a directory. The syntax is similar to pycompile just the name is changed like:

Code:
import compileall
compileall.compile_dir("mylib", force=1)

May be this will help http://effbot.org/zone/python-compile.htm
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

RE: Compiling Your Python Project #9
(06-23-2013, 10:00 AM)zero-uplink Wrote: I have another question.
When we import a module/library for the first time, python do compile it into .pyc right?
But why not the script that imported the module or library?
It seems to me that python only compile something that is being imported. Not the module or script which imported it.

May be a silly question too. But I really don't know.

Let me explain this a bit. A programming language can have a lot of different implementations, in Python these are i.e. IronPython, CPython, Jython, ...
Depending on the implementation the process of compiling and interpreting is handled differently.

The .pyc files are a result of the CPython implementation.
Everytime you type in "python myfile.py" into your console the script is compiled into .pyc, which is a bytecode. Bytecode is an intermediate language that is afterwards interpreted by a virtual machine.
So everytime you run the script, it is compiled again. That costs time (at startup).

If you know you want to run your script very often without the need of recompiling it, you can compile it by yourself and run the .pyc files instead. So you save the time of compilation when running the script.
That's the only difference. But every .py file gets compiled in one way or the other.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: Compiling Your Python Project #10
and for the lazy mofo's like myself, I present my I'm too lazy to type all this shit out everytime I need to compile file:

with sys.argv
Code:
import sys
import py_compile

if(len(sys.argv) == 2):
    print("usage: ./compile.py <location and file name>")
    file = sys.argv[1]
    py_compile.compile(file)
else:
    print("usage: ./compile.py <location and file name>")

using input() instead
Code:
import py_compile

file = input("Enter the python location and file name: ")
py_compile.compile(file)
A Serious Newbies Guide to the Underground v3
http://www.hackcommunity.com/Thread-A-Se...-v3-Part-1

Reply






Users browsing this thread: 1 Guest(s)