LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-16-2013, 09:06 PM   #1
fmillion
Member
 
Registered: Nov 2006
Posts: 93

Rep: Reputation: 27
How to shrink a Python 2.7.3 installation for low-storage system?


Hi,

I'm working on a project involving building a Linux-based controller system, and I want to use Python to write some scripts and some controller code.

I'm working with an x86-based system, so I don't need to do anything really odd. No compiling for ARM here or anything to worry about - it books Linux and runs it just as a PC does.

However, I only have 128MB of flash-based storage to work with for the core OS in the final system. I have 256MB of RAM and the storage limitation is not a problem at all for anything else, except Python's default installation wants to eat up well over 200MB.

Most of this is in /usr/lib/python-2.7, with a large chunk (almost 100MB) being in /usr/lib/python-2.7/lib-dynload.

I've read you can remove things like the "test" directory and such but I've only been able to successfully bring the install down to about 170MB.

It seems to me there has to be a way to reduce the size of this installation. Python is a really good language to accomplish the tasks I'm doing, but I don't have the room to install it in its full implementation.

Is there any good information available on how I can shrink the installation down as much as possible? I could probably spare a max of say 30MB or so for Python. (The rest of the OS is LFS-based and fits in under 70MB.) We obviously want to keep a little space free for logfiles or whatnot.

(Please, no obvious answers like "upgrade the storage" - that's not an option at this point. I'm looking to see if there's actually a way to trim down a Python installation.)

It seems that there would be some way to achieve this - after all, Python3's installation fits in about 90MB, and (for comparison's sake) PHP5 fits into 6MB! (There's of course also implementations for things like Symbian/S60 that fit into a couple of MB...) Just seems unlikely that there's no way at all to reduce this installation. As an absolute last resort I could write some of the scripts in PHP but Python is just a lot more suited for the task at hand.

Advice greatly appreciated!

F
 
Old 02-17-2013, 12:07 AM   #2
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,513

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
No python "Development Environment" is required to run your application.

A basic run-time python, see e.g. the Fedora 18 "run time" :
The python-2.7.3 package is 90 kB installed.

And python-libs-2.7.3 : A 5.5 MB rpm, 24 MB installed >
> 2200 files, and you may even not need all those.


I guess you can set up a "development computer" with your target OS.
And develop the app on a full python install.
Then transfer the result + the dependencies to the "Controller system".

-
 
Old 02-17-2013, 07:45 AM   #3
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
The most simple (and radial) way to shrink Python installation is not install Python at all. But you still want to write your software in Python... So you can install Python on your development box, and then use pyinstaller http://www.pyinstaller.org/ to pick up only python files that your code will actually use
 
1 members found this post helpful.
Old 02-26-2013, 02:07 PM   #4
fmillion
Member
 
Registered: Nov 2006
Posts: 93

Original Poster
Rep: Reputation: 27
Thanks for the pointers...

knudfl: Your post intrigued me to research further about why my Python install is so huge. Turns out it was simple - the shared Python library wasn't being compiled, thus all my .so files were huge. (5MB for time.so did seem kind of big to me!)

I recompiled with --enable-shared and this brought the full install down to 70MB.

Then I did all of the following:

* Use "strip" to remove all debugging symbols from the shared library and from all libraries in lib-dynload
* Removed the test directory
* Removed the .py source files for the libraries and the .pyo optimized versions (after reading docs, there's no advantage to using the optimized versions over the pyc versions)

All of this brought the install down to 28MB - on par with the package size you mentioned!

Some selective library removal I'm sure will reduce this even more. I've now met my goal. :-)

Thanks!

F

Last edited by fmillion; 02-26-2013 at 02:09 PM.
 
Old 02-26-2013, 02:16 PM   #5
fmillion
Member
 
Registered: Nov 2006
Posts: 93

Original Poster
Rep: Reputation: 27
So, just one more update.

I removed all of the following libs: distutils, idlelib, lib-tk, lib2to3, unittest, and some items in the config directory.

I also removed the manpage.

All of this got my install down to a nice and slim 17MB.

Success!

F

Last edited by fmillion; 02-26-2013 at 02:19 PM.
 
  


Reply



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
Server with low energy use and personal file storage thallium Linux - Hardware 3 10-20-2012 12:48 PM
[SOLVED] Which is best storage system used EMC2 are NETAPPS storage sanjay87 Linux - Server 1 04-16-2012 08:27 AM
low storage space? briced Linux - General 1 05-11-2008 08:59 AM
Problem during installation redhat 9 shrink i386 SkeleToR.cZ Linux - Newbie 3 03-24-2006 07:13 AM
shrink file system with out unmounting ravikumarG AIX 2 06-29-2005 08:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:35 PM.

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