Can .py be complied?

M

monkey

Hi all, I am new to programming, already have a glace on introduction of
c++, java and finally decided on python. But I found that the .py file is
just like the source file, how can I make a program without revealing its
source? (may be my question is a little bit stupid)
 
H

Harlin Seritt

Hi monkey,

Not a stupid question especially if you're trying to create commercial
software and don't want to reveal your source. At any rate, you can use
py2exe to create a .exe file. It does have some cons to it since you
are compiling an interpreted script but it works fine in this capacity.
If you would like to obfuscate your code (disguise it) without an
executable you can try pyobfuscate as well. Just Google for these two
and you'll find easily.

Harlin Seritt
 
M

Maurice LING

monkey said:
Hi all, I am new to programming, already have a glace on introduction of
c++, java and finally decided on python. But I found that the .py file is
just like the source file, how can I make a program without revealing its
source? (may be my question is a little bit stupid)

It is generally not very easy or straight-forward. The developers of
CPython had generally intended that the source codes be the actual
distribution, and is not likely to change. (see the thread on "bytecode
non-backcompatibility")

For now, you can use pyfreeze to snap the application, which is to
bundle your application to a python interpreter (bootstrapping) as a
package but this will not create a portable application. You can only
run the application on the native system that it is frozen on. For
example, if i freeze my application on Mac OSX, I won't be able to run
that on MS Windows. Freezing bootstraps the system's python onto the
application.

If your application does not use any C modules, you can try to use
Jython instead. Program in python but use jythonc to convert it into
Java source files and package it into Java JAR files, then you will only
need to release the JAR files without needing to release your codes.

Cheers
Maurice
 
R

ryan

I don't know the exact details, but try using the compiled Python
scripts (bytecode). I believe they are semi-optimized and platform
independent. They are the .pyc and .pyo files generated when the script
is run.
 
M

monkey

Thanks all of you guys, I found that python newsgroup is of wealthy
knowledge:
If you would like to obfuscate your code (disguise it) without an
executable you can try pyobfuscate as well.

Harlin Seritt

Yes, I want more options. Since the python doc mentioned py2exe only, and it
is difficult to understand how it work.(may be you guys know C and make
file, but I am still foolish here...)
It is generally not very easy or straight-forward.
For now, you can use pyfreeze to snap the application.....
If your application does not use any C modules, you can try to use
Jython instead.

Cheers
Maurice

If using Jython to complie, is the end-user need JRE instead of Python
installed, or need both of them?
I don't know the exact details, but try using the compiled Python
scripts (bytecode). I believe they are semi-optimized and platform
independent. They are the .pyc and .pyo files generated when the script
is run.

ryan@ryankaskel

Is that means a .py convert to .pyc or .pyo, without the need of "make file"
as using py2exe?
 
F

Filip Dreger

If using Jython to complie, is the end-user need JRE instead of
Python
installed, or need both of them?

Only JRE. Just like Java.
Is that means a .py convert to .pyc or .pyo, without the need of
"make file"
as using py2exe?

..pyc files are generated every time a module (any .py file can be a
module) is imported. So if you have a program, say, example.py, you
just start the python interpreter and write:And then example.pyc will appear beside example.py. This new file does
not require example.py (you can even delete it), and works on any
computer with Python installed (on Windows you can just double-click
it)
If you start the Python interpreter using:
python -OO (if you are using Windows, you shoud start the interpreter
from the command line, probably something like:
c:
cd \
python24\python -OO)
and then import your example.py, you will get a file example.pyo,
which is also stripped of any documentation strings (a bit harder to
decode).

regards,
Filip Dreger
 
K

Kent Johnson

monkey said:
If using Jython to complie, is the end-user need JRE instead of Python
installed, or need both of them?

The end-user needs the JRE, not Python.

Kent
 
M

Maksim Kasimov

Maurice LING said:
If your application does not use any C modules, you can try to use
Jython instead. Program in python but use jythonc to convert it into
Java source files and package it into Java JAR files, then you will only
need to release the JAR files without needing to release your codes.

using Jython will not helps to hide your sources - jar-files are also easy
to decompile and to receive the source code (it will even looks like
original).
To avoid releasing your java-code (as far as it possible), the jar-files are
also necessary for processing by obfuscators
 
M

monkey

And then example.pyc will appear beside example.py. This new file does
not require example.py (you can even delete it), and works on any
computer with Python installed

Filip, you can read through my mind (-: You just told me what I want to know
exactly, even I can't ask the question correctly. Thx..
python24\python -OO)
and then import your example.py, you will get a file example.pyo,
which is also stripped of any documentation strings (a bit harder to
decode).

Is .pyo still not secure for serious purpose? The -OO function refer to
which area of python that I can read a doc in details?
The end-user needs the JRE, not Python.

Kent

Actually I still not dare to touch Jython, because I am still digging python
now. But the JRE may not attract end-user, because it is still associate
with "slow" and "eating much system resource", although Java is sure a
respectfully programming language. What do you think?
 
G

Grant Edwards

Yes, I want more options. Since the python doc mentioned
py2exe only, and it is difficult to understand how it
work.(may be you guys know C and make file, but I am still
foolish here...)

py2exe has nothing to do with C or make files. You create a
setup.py file containing a couple lines of python. You run
that python program, and you end up with an .exe file and some
associated .dll files. I typically use inno-setup to create an
installer.exe that creates a desktop icon and start-menu entry,
but that's optional.
Is that means a .py convert to .pyc or .pyo, without the need
of "make file" as using py2exe?

Huh? You don't need a make file for py2exe.
 
M

monkey

py2exe has nothing to do with C or make files. You create a
setup.py file containing a couple lines of python. You run
that python program, and you end up with an .exe file and some
associated .dll files. I typically use inno-setup to create an
installer.exe that creates a desktop icon and start-menu entry,
but that's optional.

Is py2exe used to make a .exe file to install .py, or make the self-contain
..exe file of the program itself?
 
G

Grant Edwards

Is py2exe used to make a .exe file to install .py, or make the self-contain
.exe file of the program itself?


The latter. It's not completely self contained, there is an
...exe and some dll files that need to be distributed together.
It's explained very clearly by the py2exe web site:

http://starship.python.net/crew/theller/py2exe/

Never used google before? Just go to www.google.com and type
in py2exe. Click "search". It's the first hit.
 
S

steve.leach

Harlin said:
Hi monkey,

Not a stupid question especially if you're trying to create commercial
software and don't want to reveal your source. At any rate, you can use
py2exe to create a .exe file. It does have some cons to it since you

Some very severe cons considering that would mean his code would only
run on a certain infamous legacy operating system that will remain
unnamed. The last I checked, ".exe" files were rather useless on most
operating systems.
 
B

beliavsky

IMO the fact that so many people ask

"How can I create executables in Python on Windows"

indicates that standard "batteries included" Windows Python
distribution is missing a vital battery. There are tools such as
py2exe, but this functionality should be built-in, so that a newbie to
Python can just download it, type

python -o foo.exe foo.py

at the command line, and get an executable, without any further effort.
 
S

steve.leach

python -o foo.exe foo.py
at the command line, and get an executable, without any further effort.

Hence making the resulting program useless to users of most operating
systems.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top