LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-31-2011, 06:24 AM   #1
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 749

Rep: Reputation: 73
Can .pyc and .pyo files be deleted?


Hello, I have a lot of .pyc and .pyo files and I really need the space. I was wonder if I can remove them as I know python will create them automatically.

At the moment, I need to make sure I have the space and only this files I can delete... should this be fine?

Also I know they are recreated, but not sure how safe it is just to remove them.
 
Old 01-31-2011, 11:06 PM   #2
prodev05
Member
 
Registered: Jul 2009
Location: Planet Earth
Distribution: Unix & Linux Variants
Posts: 304

Rep: Reputation: 20
No don't do it. Remove the old kernel and old modules. That will give you enough space. Which partition is populated ? Could you pl give me the output.
 
Old 02-01-2011, 01:12 AM   #3
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 749

Original Poster
Rep: Reputation: 73
I need to know if they are safe to delete or not, if not why they are not safe to delete, don't tell me about crap which I didnt ask.

Last edited by robertjinx; 02-01-2011 at 10:09 AM.
 
Old 02-08-2011, 05:44 PM   #4
Julian Andrews
LQ Newbie
 
Registered: Jan 2011
Distribution: Ubuntu
Posts: 21

Rep: Reputation: 13
My understanding is that as long as python can find the .py files it will automatically compile .pyo and .pyc files as needed (on module import). I know for sure that for any .pyo/.pyc files for your own python code you can erase them completely safely, I do that all the time.

If you're talking about the system files, I would be a little careful, and at least make sure that the .py file exists for any .pyo/.pyc file you want to erase. I just ran a test where I moved /usr/lib/python2.6/xmllib.pyc and ran python and imported xmllib(I chose the module totally at random) and the .pyc file wasn't recreated, but the module imported fine. I did the same thing as root, and the .pyc file was recreated, so this would suggest that the process is fairly safe, at least if you have the .py files.

As a side note, you can use the -B command line argument to python, or
Code:
sys.dont_write_bytecode = True
if you want your code not to write bytecode for imported modules. This leads to the obvious performance penalty.

Anyway, I can't make any guarantees, but my quick test suggests you should be fine. I might run a similar test with a .pyo file just to be paranoid - and of course don't erase any bytecode files if you don't have th corresponding .py file somewhere! Also, don't expect to free up much space this way! I checked on my own system and across two python installs (one on windows and one in linux) all my .pyc and .pyo files combined add up to less than 100M!
 
Old 02-08-2011, 11:04 PM   #5
prodev05
Member
 
Registered: Jul 2009
Location: Planet Earth
Distribution: Unix & Linux Variants
Posts: 304

Rep: Reputation: 20
Quote:
Originally Posted by Julian Andrews View Post
My understanding is that as long as python can find the .py files it will automatically compile .pyo and .pyc files as needed (on module import). I know for sure that for any .pyo/.pyc files for your own python code you can erase them completely safely, I do that all the time.

If you're talking about the system files, I would be a little careful, and at least make sure that the .py file exists for any .pyo/.pyc file you want to erase. I just ran a test where I moved /usr/lib/python2.6/xmllib.pyc and ran python and imported xmllib(I chose the module totally at random) and the .pyc file wasn't recreated, but the module imported fine. I did the same thing as root, and the .pyc file was recreated, so this would suggest that the process is fairly safe, at least if you have the .py files.

As a side note, you can use the -B command line argument to python, or
Code:
sys.dont_write_bytecode = True
if you want your code not to write bytecode for imported modules. This leads to the obvious performance penalty.

Anyway, I can't make any guarantees, but my quick test suggests you should be fine. I might run a similar test with a .pyo file just to be paranoid - and of course don't erase any bytecode files if you don't have th corresponding .py file somewhere! Also, don't expect to free up much space this way! I checked on my own system and across two python installs (one on windows and one in linux) all my .pyc and .pyo files combined add up to less than 100M!
wonderful explanation
 
Old 02-09-2011, 02:59 PM   #6
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 749

Original Poster
Rep: Reputation: 73
Less than 100M is fine.. and thanks, I will test it
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleted files on a SMB-share - Files gone, space still allocated - Fedora 10 Zwentendorf Linux - Server 4 03-01-2009 05:04 AM
pysol_23.pyc file missing....Pysol card game FC4 rob.linux Linux - Games 0 12-11-2006 02:34 AM
Mepis, copy files to thumb drive, files deleted? vremenno Linux - Newbie 6 09-15-2006 11:21 PM
Python doesn't make pyc files GiantBucket Programming 2 03-13-2006 05:04 AM
How to delete the destination files while the source files deleted in cp -u ? myunicom Linux - General 4 09-26-2003 01:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration