can I delete one of *.py *.pyc *.pyo in /usr/lib/python2.3 ?

M

Miernik

On my Debian GNU/Linux system I have Python 2.3 installed in
/usr/lib/python2.3/ where most Python system files like

/usr/lib/python2.3/gzip.py
/usr/lib/python2.3/gzip.pyc
/usr/lib/python2.3/gzip.pyo

live, besides of course /usr/bin/python2.3

I noticed that all those files come in three "flavours":
*.py *.pyc *.pyo

Is it possible that only one "flavour" of these files is needed, and I can
delete the remaining two, any my Python installation will still work?

The whole /usr/lib/python2.3/ directory takes up over 15 MB, deleting
two "flavours" would save about 10 MB on my system, and that would help
me much as I am trying to fit my system on a 256 MB SD card, to make it
quiet (hard disks are noisy).

Can I just do
cd /usr/lib/python2.3/ && rm -rf *.py && rm -rf *.pyc
for example, and everything will still work as before?
 
L

Lucas Raab

Miernik said:
On my Debian GNU/Linux system I have Python 2.3 installed in
/usr/lib/python2.3/ where most Python system files like

/usr/lib/python2.3/gzip.py
/usr/lib/python2.3/gzip.pyc
/usr/lib/python2.3/gzip.pyo

live, besides of course /usr/bin/python2.3

I noticed that all those files come in three "flavours":
*.py *.pyc *.pyo

Is it possible that only one "flavour" of these files is needed, and I can
delete the remaining two, any my Python installation will still work?

The whole /usr/lib/python2.3/ directory takes up over 15 MB, deleting
two "flavours" would save about 10 MB on my system, and that would help
me much as I am trying to fit my system on a 256 MB SD card, to make it
quiet (hard disks are noisy).

Can I just do
cd /usr/lib/python2.3/ && rm -rf *.py && rm -rf *.pyc
for example, and everything will still work as before?

You can delete any two of the three and you shouldn't run into any
problems. However, the .py files are the source code and .pyc and .pyo
are compiled Python files. The .pyc and .pyo files will load faster
because they are compiled. Also, if you keep the .py files and then
execute them, .pyc files will be generated. In short, I would keep the
..pyc files and delete the others.

--
--------------------------
Lucas Raab
lvraab"@"earthlink.net
dotpyFE"@"gmail.com
AIM: Phoenix11890
MSN: dotpyfe "@" gmail.com
IRC: lvraab
ICQ: 324767918
Yahoo: Phoenix11890
 
P

Pierre Barbier de Reuille

Miernik a écrit :
On my Debian GNU/Linux system I have Python 2.3 installed in [...]

I noticed that all those files come in three "flavours":
*.py *.pyc *.pyo

Is it possible that only one "flavour" of these files is needed, and I can
delete the remaining two, any my Python installation will still work?

Well, I would greatly discourage that ! First, if you erase the *.py,
you won't be able to get detailed information on the traceback (like
actual code causing throwing the exception) as only the filename/line is
kept in the .pyc or .pyo. Then, if you erase the .pyo that means you
don't want to use the optimized version of the modules (why not ... but
it will be at the cost of performances). At last, if you keep only the
..pyo you won't be able to run programs without the optimization.

So let's summarize :
1 - you keep only .py files: everything will work but Python will have
to recompile the modules everytime it's used first
2 - you keep only .pyc files: two problems: first you won't be able to
launch Python with the "-O" option (i.e. optimize) because it will look
for .py or .pyo files, then if any exception is thrown in one of the
modules, you won't be able to use the very good pdb module with code
information and all.
3 - you keep only .pyo files: similar to keeping only the .pyc files
but you won't be able to launch Python without the "-O" !
The whole /usr/lib/python2.3/ directory takes up over 15 MB, deleting
two "flavours" would save about 10 MB on my system, and that would help
me much as I am trying to fit my system on a 256 MB SD card, to make it
quiet (hard disks are noisy).

Can I just do
cd /usr/lib/python2.3/ && rm -rf *.py && rm -rf *.pyc
for example, and everything will still work as before?

Well, if you don't care about performances, the best to do is (using zsh
;) ):

cd /usr/lib/python2.3 && rm -f **/*.py{o,c}

Pierre
 
P

Pierre Barbier de Reuille

Lucas Raab a écrit :
Miernik wrote:
[...]

You can delete any two of the three and you shouldn't run into any
problems. However, the .py files are the source code and .pyc and .pyo
are compiled Python files. The .pyc and .pyo files will load faster
because they are compiled. Also, if you keep the .py files and then
execute them, .pyc files will be generated. In short, I would keep the
.pyc files and delete the others.

As I said in my other post, if you ever run python using the "-O" and
have neither the .py nor the .pyo file, it won't load the module (even
if the .pyc is present ...)

Pierre
 
S

Scott David Daniels

Miernik said:
On my Debian GNU/Linux system I have Python 2.3 installed in
/usr/lib/python2.3/ where most Python system files like

/usr/lib/python2.3/gzip.py
/usr/lib/python2.3/gzip.pyc
/usr/lib/python2.3/gzip.pyo

live, besides of course /usr/bin/python2.3

I noticed that all those files come in three "flavours":
*.py *.pyc *.pyo

Is it possible that only one "flavour" of these files is needed, and I can
delete the remaining two, any my Python installation will still work?

The whole /usr/lib/python2.3/ directory takes up over 15 MB, deleting
two "flavours" would save about 10 MB on my system, and that would help
me much as I am trying to fit my system on a 256 MB SD card, to make it
quiet (hard disks are noisy).

Can I just do
cd /usr/lib/python2.3/ && rm -rf *.py && rm -rf *.pyc
for example, and everything will still work as before?
You can put them all in a .zip (repeating the structure), named
python23.zip, and put that zip file where the search path looks
for it. Having built python23.zip, you can delete all the
..py, .pyc, .pyo files you put in the zip. Compress them
using "DEFLATE", since Python's zipfile module doesn't do
BZIP2 compression (yet).

--Scott David Daniels
(e-mail address removed)
 
M

Magnus Lycka

Miernik said:
I noticed that all those files come in three "flavours":
*.py *.pyc *.pyo

Is it possible that only one "flavour" of these files is needed, and I can
delete the remaining two, any my Python installation will still work?

If you remove all *.pyc and *.pyo, they will be regenerated as needed.
If your code only uses a small fraction of the standard library, you
will save quite some space here. The only reason they are generated on
installation is to save some runtime on first use of a module, and
perhaps aviod the surprise of an installation that continues to grow
after a completed installation...

I'm not sure about this, but if you have plenty of RAM (you will
trade HD noise for fan noise I guess) you might get the *.py[co] files
to stay on a RAM disk. (If nothing else works, I guess you could have
your system mirror your entire Python directory structure to RAM disk
at boot time.) Then you should have a Python system which will get
really fast once most modules have been recompiled--until you reboot...
 
S

Scott David Daniels

Magnus said:
If you remove all *.pyc and *.pyo, they will be regenerated as needed.
If your code only uses a small fraction of the standard library, you
will save quite some space here. The only reason they are generated on
installation is to save some runtime on first use of a module, and
perhaps aviod the surprise of an installation that continues to grow
after a completed installation...
Another reason is to allow efficient access to python for users who
do not have permission to create files (the .pyc and .pyo files) in
Python's library directories.

--Scott David Daniels
(e-mail address removed)
 

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,776
Messages
2,569,603
Members
45,190
Latest member
Martindap

Latest Threads

Top