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

Pierre Barbier de Reuille pierre.barbier at cirad.fr
Sat Aug 20 16:58:38 CEST 2005


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



More information about the Python-list mailing list