473,287 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Can .py be complied?

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)
Jul 19 '05 #1
30 2075
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

Jul 19 '05 #2
monkey wrote:
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
Jul 19 '05 #3
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.

Jul 19 '05 #4

ry**@ryankaskel.com wrote:
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.


Okay, I found this documentation
<http://fux0r.phathookups.com/programming-tutorials/Python/tut/node43.html>.
It hides the source but you still need Python installed on the system
running the bytecode.

Jul 19 '05 #5
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?
Jul 19 '05 #6

U¿ytkownik "monkey" <m@m.com> napisa³ w wiadomo¶ci
news:42**********@rain.i-cable.com...
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.
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.

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:
import example

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
Jul 19 '05 #7
monkey wrote:
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?


The end-user needs the JRE, not Python.

Kent
Jul 19 '05 #8
ry**@ryankaskel.com wrote:
ry**@ryankaskel.com wrote:
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.

Okay, I found this documentation
<http://fux0r.phathookups.com/programming-tutorials/Python/tut/node43.html>.
It hides the source but you still need Python installed on the system
running the bytecode.


But those files can be decompyled.

--
--------------------------
Lucas Raab
lvraab"@"earthlink.net
dotpyFE"@"gmail.com
AIM: Phoenix11890
MSN: dotpyfe"@"gmail.com
IRC: lvraab
ICQ: 324767918
Yahoo: Phoenix11890
Jul 19 '05 #9

"Maurice LING" <ma*********@acm.org> wrote:
news:d4**********@domitilla.aioe.org...
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
--
Best regards,
Maksim Kasimov
mailto: ka*****@i.com.ua
Jul 19 '05 #10
> 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?
Jul 19 '05 #11
>
But those files can be decompyled.


Hi, so which way to go?
Jul 19 '05 #12
On 2005-04-27, monkey <m@m.com> wrote:
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.

--
Grant Edwards grante Yow! I'd like TRAINED
at SEALS and a CONVERTIBLE on
visi.com my doorstep by NOON!!
Jul 19 '05 #13
> 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?
Jul 19 '05 #14
On 2005-04-27, monkey <m@m.com> wrote:
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?

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.

--
Grant Edwards grante Yow! Is something VIOLENT
at going to happen to a
visi.com GARBAGE CAN?
Jul 19 '05 #15
Harlin Seritt wrote:
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.
Jul 19 '05 #16
Thx very much, I got the point now ( ;
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.

--
Grant Edwards grante Yow! Is something VIOLENT at going to happen to a
visi.com GARBAGE CAN?

Jul 19 '05 #17
I've just tried to build both console and windows exe and
it works just fine

monkey wrote:
Thx very much, I got the point now ( ;

Jul 19 '05 #18
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.

Jul 19 '05 #19
> 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.
Jul 19 '05 #20
steve.leach wrote:
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.


In close sourced development, which most corporates may prefer, yes, the
resulting program is useless to users of most operating systems.

In open sourced developement, it is still a good feature to have. At
least for distribution to end users or as trial.

To end users, they don't care, as long as they can click and run the
program they need.

To developers, if the codes are close source, nothing can be done anyway
even if you have the codes, licensing agreements and contracts usually
forbids everything. If the codes are open source, you will get the codes
anyway and do according to the limits of the licence.

maurice
Jul 19 '05 #21
> python -o foo.exe foo.py


Is that a real command that can be use?
Jul 19 '05 #22
jfj
be*******@aol.com wrote:
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.

Since this is about windows and windows users just want everything in
".exe" form (no matter if it also contains spyware), and they don't care
about the size of it (they just want the damn exe) and since there is
zero chance that python will be included in the next windows
distribution but these people still want the exe (they do, really),
I think I have a convenient solution to give it to them.

/* small program in C in self extracting archive
*/
if (have_application ("Python")) {
have_python:
system ("python.exe my_application.py")
} else {
printf ("This software requires python. Wait until all the
necessary components are being installed\n");
download_python_from_python_org();
system ("install_python.exe");
goto have_python;
}
Seriously, people who want executables wouldn't notice the difference.
jfj

Jul 19 '05 #23
On 28 Apr 2005 07:01:50 -0700, be*******@aol.com <be*******@aol.com> wrote:
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.


It indicates to *me* that people aren't reading the FAQ. ;-)

--
Cheers,
Simon B,
si***@brunningonline.net,
http://www.brunningonline.net/simon/blog/
Jul 19 '05 #24
steve.leach wrote:
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.


Let's ignore for the moment whether including py2exe as a "battery" is a
desirable thing from an abstract point of view. We may legitimately
differ about that.

We should not forget in our enthusiasm for open source that while "users
of most operating systems" might not find py2exe useful, "most users of
operating systems" may well, since Windows users outnumber the rest
several times.

There's nothing wrong with open source projects catering to a market,
and there's nothing wrong with running open source software on a
proprietary operating system. To behave otherwise might reduce the
growth opportunities for Python and its community.

no-zealotry-please-ly y'rs - steve
--
Steve Holden +1 703 861 4237 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/

Jul 19 '05 #25
Steve Holden <st***@holdenweb.com> writes:
[...]
There's nothing wrong with open source projects catering to a market,
and there's nothing wrong with running open source software on a
proprietary operating system. To behave otherwise might reduce the
growth opportunities for Python and its community.

no-zealotry-please-ly y'rs - steve

[...]

I'm hesitant to label everybody who disagrees with you (and me) on
that a zealot. Though I tend to take the same side you do, I'm not
entirely sure it's not just laziness on my part that I think that way.

Seems to me that holding opinions such as "it's a bad thing to support
open source software on closed source systems, and you should not do
it, for the common good" is far from crazy, even though I don't
currently happen to hold that view.
John

Jul 19 '05 #26
jfj <jf*@freemail.gr> writes:
[...]
/* small program in C in self extracting archive
*/
if (have_application ("Python")) {
have_python:
system ("python.exe my_application.py")
} else {
printf ("This software requires python. Wait until all the
necessary components are being installed\n");
download_python_from_python_org();
system ("install_python.exe");
goto have_python;
}
Seriously, people who want executables wouldn't notice the difference.


Until they install the next program that does this.
John

Jul 19 '05 #27
John J. Lee wrote:
Steve Holden <st***@holdenweb.com> writes:
[...]
There's nothing wrong with open source projects catering to a market,
and there's nothing wrong with running open source software on a
proprietary operating system. To behave otherwise might reduce the
growth opportunities for Python and its community.

no-zealotry-please-ly y'rs - steve


[...]

I'm hesitant to label everybody who disagrees with you (and me) on
that a zealot. Though I tend to take the same side you do, I'm not
entirely sure it's not just laziness on my part that I think that way.

Seems to me that holding opinions such as "it's a bad thing to support
open source software on closed source systems, and you should not do
it, for the common good" is far from crazy, even though I don't
currently happen to hold that view.

Well, we appear to agree. Please note I wasn't labelling anyone a
zealot, simply implying that I didn't want the discussion to descend to
blind repetitions of principle with no supporting arguments.

I have no problem with others taking a different view from mine on this
issue, though I reserve the right to disagree with them. My own view is
that open source (Python included) wouldn't be anywhere near as advanced
and popular as it is if it hadn't been ported to the majority platform,
and that this actually positions it better for eventual world domination
:-). There's a reason Microsoft are fighting Linux with FUD.

Let's also not forget that at PyCon, (I am told) when Jim Hugunin asked
for a show of hands as to who principally developed for Windows
platforms, *Guido* raised his hand.

regards
Steve
--
Steve Holden +1 703 861 4237 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/

Jul 19 '05 #28
jj*@pobox.com (John J. Lee) writes:

[snap]
Until they install the next program that does this.


If we talk about _real_ users from the _real_ world, the most of them
would just kill the app (or what is the name for stopping running
program in w32) when the download begins[1] :)

[1] 'hey, is that a spyware or what? what takes so darn long?'

--
http://www.pdemb.prv.pl
Jul 19 '05 #29
jfj <jf*@freemail.gr> writes:
/* small program in C in self extracting archive
*/
if (have_application ("Python")) {
have_python:
system ("python.exe my_application.py")
} else {
printf ("This software requires python. Wait until all the
necessary components are being installed\n");
download_python_from_python_org();
system ("install_python.exe");
goto have_python;
}


Goto. Ugh.

if (!have_application("Python")) {
printf ("This software requires python. Wait until all the
necessary components are being installed\n");
download_python_from_python_org();
system ("install_python.exe");
}
system("python.exe my_application.py");

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 19 '05 #30
Steve Holden <st***@holdenweb.com> writes:
John J. Lee wrote: [...]
I'm hesitant to label everybody who disagrees with you (and me) on
that a zealot. Though I tend to take the same side you do, I'm not

[...] Well, we appear to agree. Please note I wasn't labelling anyone a
zealot, simply implying that I didn't want the discussion to descend
to blind repetitions of principle with no supporting arguments.

[...]

Sorry, I wasn't reading carefully.

I suppose really my thought was directed more at the programming world
in general, which often feels free to label free software advocates as
loonies (I've been guilty of this myself, I'm sure). Of course, lots
of them *are* loonies, but that's beside the point. ;-)
John
Jul 19 '05 #31

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
by: Pmb | last post by:
I'm confused as to what the compiler error message I'm getting is refering to. Can someone take a gander and let me know what I did wrong? The program is below. When I compile it I get the...
12
by: kim | last post by:
The c program is an example and should be correct. I tried to compile the c file with MS studio 6.0. But failed with the several err and warning messages. Does anyone know how to make it work?...
5
by: Martin | last post by:
Hi All, Im looking forward for info whether VB.NET complied application would run in Windows 98 or not ? Does any one have tried to do so ?? Regards, Martin
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.