LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to shrink a Python 2.7.3 installation for low-storage system? (https://www.linuxquestions.org/questions/linux-software-2/how-to-shrink-a-python-2-7-3-installation-for-low-storage-system-4175450487/)

fmillion 02-16-2013 09:06 PM

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

knudfl 02-17-2013 12:07 AM

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".

-

Valery Reznic 02-17-2013 07:45 AM

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

fmillion 02-26-2013 02:07 PM

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

fmillion 02-26-2013 02:16 PM

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


All times are GMT -5. The time now is 02:35 AM.