compatbility of .pyc files

B

Blair Hall

I have a requirement to prevent 'accidental' tampering
with some software written in Python. If I ensure that all
of the modules concerned are compiled into .pyc's, and remove
the .py's to another location, then I should be safe until
the next upgrade of the Python interpretter.

My questions:

Are the .pyc's usable without recompilation between 'minor'
releases of the interpretter (e.g., 2.3.1 -> 2.3.2 -> etc)?

I presume that the .pyc's are NOT compatible
across more major releases (e.g., 2.3.x -> 2.4.x)?

Is there a hard and fast rule about compatibility across
releases that I can rely on?
 
P

Paul Rubin

I find myself having to write some code on Windows :-(. To alleviate
the pain, at least I get to use Python for some of it.

I'm trying to write a simple application, say "eggs.py". It pops a
tkinter gui and lets the user do some stuff. The system has Python
installed so I don't care about wrapping it in a .exe file or anything
like that. But I'd like to make a desktop icon for eggs.py and let the
user double-click it and run the app without also getting a DOS box on
the screen.

Is there a simple way to do that? I didn't see anything in the Python
docs about it. I suspect that this is really a dumb Windows question,
but I avoid Windows whenever I can, so most anything I can ask about it
is probably dumb.

Thanks much.
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Blair said:
Are the .pyc's usable without recompilation between 'minor'
releases of the interpretter (e.g., 2.3.1 -> 2.3.2 -> etc)?
Yes.

I presume that the .pyc's are NOT compatible
across more major releases (e.g., 2.3.x -> 2.4.x)?
Correct.

Is there a hard and fast rule about compatibility across
releases that I can rely on?

Each Python version uses a "magic", as returned by
imp.get_magic(). Whenever that changes (and it will at
worst change between 2.x, 2.x+1), you need to recompile
the .pyc files.

If you pass it an "old" pyc file (i.e. one with an
incorrect magic), Python will silently ignore the .pyc
file, use the source, and attempt to regenerate the
..pyc file.

Regards,
Martin
 
J

Jeremy Bowers

I have a requirement to prevent 'accidental' tampering
with some software written in Python. If I ensure that all
of the modules concerned are compiled into .pyc's, and remove
the .py's to another location, then I should be safe until
the next upgrade of the Python interpretter.

Depending on how "scare quote-y" the scare quotes are, if you're really
out to avoid accidental tampering, why not just set the *.py files to
read-only?

Beyond that you get into rapidly diminishing returns; removing the .py
files is feasible if you have some semblance of control over the
interpreter, beyond that and you're usually better off with a binding
legal agreement.
 
M

Martin Franklin

Paul said:
I find myself having to write some code on Windows :-(. To alleviate
the pain, at least I get to use Python for some of it.

I'm trying to write a simple application, say "eggs.py". It pops a
tkinter gui and lets the user do some stuff. The system has Python
installed so I don't care about wrapping it in a .exe file or anything
like that. But I'd like to make a desktop icon for eggs.py and let the
user double-click it and run the app without also getting a DOS box on
the screen.

Is there a simple way to do that? I didn't see anything in the Python
docs about it. I suspect that this is really a dumb Windows question,
but I avoid Windows whenever I can, so most anything I can ask about it
is probably dumb.

Thanks much.

renaming the eggs.py to eggs.pyw will tell windows to use pythonw.exe
to start this python file (and will not open a console) You can then
create a shortcut in the normal way

Martin
 
V

Vincent Wehren

Paul said:
I find myself having to write some code on Windows :-(. To alleviate
the pain, at least I get to use Python for some of it.

I'm trying to write a simple application, say "eggs.py". It pops a
tkinter gui and lets the user do some stuff. The system has Python
installed so I don't care about wrapping it in a .exe file or anything
like that. But I'd like to make a desktop icon for eggs.py and let the
user double-click it and run the app without also getting a DOS box on
the screen.

Rename the file "eggs.py" to "eggs.pyw" and create a shortcut to that
file. The file will be opened using pythonw.exe instead of python.exe.
 

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

Forum statistics

Threads
474,221
Messages
2,571,133
Members
47,747
Latest member
swapote

Latest Threads

Top