Installing Lightweight Python

Discussion in 'Python' started by Nima, May 17, 2010.

  1. Nima

    Nima Guest

    I'd like to install python on an embedded system. It's a powerful x86-
    based computer with the only limitation of having a small-size flash
    ROM as its secondary storage. So there is no hard drive and the system
    is booted from the flash memory.
    The operating system, BusyBox (a flavor of Linux), and other
    applications occupy most of the flash memory. As the subject implies,
    Python isn't already installed on the box. I tried to compile/install
    python on a Linux box which roughly took 60MB of the memory. The
    maximum amount of Flash memory I'm permitted to use is about 10-20 MB.
    Is there a light-weight implementation of python which I could use? Is
    there a way to remove unnecessary modules?
    BTW,
    + I'm supposed to write a web management interface for this system
    (using python).
    + I know how to use Google!
    + I'm a newbie, so please be gentle :)
     
    Nima, May 17, 2010
    #1
    1. Advertising

  2. On Mon, May 17, 2010 at 9:12 AM, Nima <> wrote:
    > I'd like to install python on an embedded system. It's a powerful x86-
    > based computer with the only limitation of having a small-size flash
    > ROM as its secondary storage. So there is no hard drive and the system
    > is booted from the flash memory.
    > The operating system, BusyBox (a flavor of Linux), and other
    > applications occupy most of the flash memory. As the subject implies,
    > Python isn't already installed on the box. I tried to compile/install
    > python on a Linux box which roughly took 60MB of the memory. The
    > maximum amount of Flash memory I'm permitted to use is about 10-20 MB.
    > Is there a light-weight implementation of python which I could use? Is
    > there a way to remove unnecessary modules?
    > BTW,
    > + I'm supposed to write a web management interface for this system
    > (using python).
    > + I know how to use Google!
    > + I'm a newbie, so please be gentle :)
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >


    I'm not an expert, but there are probably a large-ish number of modules
    you could remove without much sacrifice on your part. Looking at the
    module list and just picking the platform-dependent ones:

    * _winreg
    * aepack
    * aetools
    * aetypes
    * AL
    * al
    * applesingle
    * autoGIL
    * buildtools
    * Carbon
    * cd
    * cfmfile
    * chunk
    * colorpicker
    * etc
    * etc
    * etc

    You could also probably remove things like 2to3, tabnanny, etc,
    and I doubt tkinter is doing you much good.

    I also recall someone at pycon talking about importing modules
    from a .zip archive. I'm not sure how easy/hard that is, but you
    may want to look at PEP 302.

    Geremy Condra
     
    geremy condra, May 17, 2010
    #2
    1. Advertising

  3. Thanks Geremy :)

    The majority of installed files (56MB of data) reside in /lib/
    python2.6/. So far, I took these steps to make it as compact as
    possible:
    1. I deleted /lib/python2.6/test directory. This reduced the size by
    20MB.
    2. I deleted .py files (cause the corresponding pyc ones are there).
    This reduced the size by 9MB.
    3. I deleted the /lib/libpython2.6.a which was 6MB.
    * By far the python runs flawlessly.

    4. I zip up the /lib/python2.6/ as python26.zip and place it in the /
    lib/ directory.
    Then I delete the /lib/python2.6/ directory. By running python, I get
    this output, though /lib/python26.zip is in the sys.path variable.

    nima@nima-desktop:~/py$ ./bin/python
    Could not find platform independent libraries <prefix>
    Could not find platform dependent libraries <exec_prefix>
    Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
    'import site' failed; use -v for traceback
    Python 2.6.5 (r265:79063, May 17 2010, 18:36:54)
    [GCC 4.4.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import sys
    >>> sys.path

    ['', '/home/nima/py/lib/python26.zip', '/home/nima/py/lib/python2.6/',
    '/home/nima/py/lib/python2.6/plat-linux2', '/home/nima/py/lib/
    python2.6/lib-tk', '/home/nima/py/lib/python2.6/lib-old', '/home/nima/
    py/lib/lib-dynload']



    On May 17, 9:00 pm, geremy condra <> wrote:
    > I'm not an expert, but there are probably a large-ish number of modules
    > you could remove without much sacrifice on your part. Looking at the
    > module list and just picking the platform-dependent ones:
    >
    > * _winreg
    > * aepack
    > * aetools
    > * aetypes
    > * AL
    > * al
    > * applesingle
    > * autoGIL
    > * buildtools
    > * Carbon
    > * cd
    > * cfmfile
    > * chunk
    > * colorpicker
    > * etc
    > * etc
    > * etc
    >
    > You could also probably remove things like 2to3, tabnanny, etc,
    > and I doubt tkinter is doing you much good.
    >
    > I also recall someone at pycon talking about importing modules
    > from a .zip archive. I'm not sure how easy/hard that is, but you
    > may want to look at PEP 302.
    >
    > Geremy Condra


    Yours sincerely,
    Nima Mohammadi
     
    Nima Mohammadi, May 17, 2010
    #3
  4. Well, I tried to run Python with -v option. It seems that python26.zip
    is partially loaded but can't be used, because zlib is "unavailable".

    nima@nima-desktop:~/py$ ./bin/python -v
    Could not find platform independent libraries <prefix>
    Could not find platform dependent libraries <exec_prefix>
    Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
    # installing zipimport hook
    import zipimport # builtin
    # installed zipimport hook
    # zipimport: found 2509 names in /home/nima/py/lib/python26.zip
    # zipimport: zlib UNAVAILABLE
    'import site' failed; traceback:
    zipimport.ZipImportError: can't decompress data; zlib not available
    # zipimport: zlib UNAVAILABLE

    Python 2.6.5 (r265:79063, May 17 2010, 18:36:54)
    [GCC 4.4.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import sys
    >>> sys.path

    ['', '/home/nima/py/lib/python26.zip', '/home/nima/py/lib/python2.6/',
    '/home/nima/py/lib/python2.6/plat-linux2', '/home/nima/py/lib/
    python2.6/lib-tk', '/home/nima/py/lib/python2.6/lib-old', '/home/nima/
    py/lib/lib-dynload']


    --
    Yours sincerely,
    Nima Mohammadi
     
    Nima Mohammadi, May 17, 2010
    #4
  5. On Mon, May 17, 2010 at 1:05 PM, Nima <> wrote:
    > Well, I tried to run Python with -v option. It seems that python26.zip is
    > partially loaded but can't be used, because zlib is "unavailable".


    is the zlib module among the files you've compressed?

    Geremy Condra
     
    geremy condra, May 17, 2010
    #5
  6. On May 18, 12:30 am, geremy condra <> wrote:
    > On Mon, May 17, 2010 at 1:05 PM, Nima <> wrote:
    > > Well, I tried to run Python with -v option. It seems that python26.zip is
    > > partially loaded but can't be used, because zlib is "unavailable".

    >
    > is the zlib module among the files you've compressed?
    >
    > Geremy Condra


    zlib.so is a shared library which is in the /lib/python2.6/lib-
    dynload/ directory.
    In PEP 273 is noted that:

    > Any files may be present in the zip archive, but only files
    > *.py and *.py[co] are available for import. Zip import of
    > dynamic modules (*.pyd, *.so) is disallowed.


    http://www.python.org/dev/peps/pep-0273/

    --
    Yours sincerely,
    Nima Mohammadi
     
    Nima Mohammadi, May 17, 2010
    #6
  7. On May 18, 1:04 am, Nima Mohammadi <> wrote:
    > On May 18, 12:30 am, geremy condra <> wrote:
    >
    > > On Mon, May 17, 2010 at 1:05 PM, Nima <> wrote:
    > > > Well, I tried to run Python with -v option. It seems that python26.zip is
    > > > partially loaded but can't be used, because zlib is "unavailable".

    >
    > > is the zlib module among the files you've compressed?

    >
    > > Geremy Condra

    >
    > zlib.so is a shared library which is in the /lib/python2.6/lib-
    > dynload/ directory.
    > In PEP 273 is noted that:
    >
    > > Any files may be present in the zip archive, but only files
    > > *.py and *.py[co] are available for import.  Zip import of
    > > dynamic modules (*.pyd, *.so) is disallowed.

    >
    > http://www.python.org/dev/peps/pep-0273/
    >
    > --
    > Yours sincerely,
    > Nima Mohammadi


    The problem is solved! I just needed to make a directory named
    "python2.6" in the /lib/ directory and copy the lib-dynload/ directory
    in it.
    Thanks for your precious help, Geremy :)

    Does anyone have the list of essentials modules to run python?
     
    Nima Mohammadi, May 17, 2010
    #7
  8. Nima

    News123 Guest

    Nima Mohammadi wrote:
    > Well, I tried to run Python with -v option. It seems that python26.zip
    > is partially loaded but can't be used, because zlib is "unavailable".

    This is normal.
    the zip library itself cannot be zipped, as it is needed to unzip and
    extract th other libs.

    >
    > nima@nima-desktop:~/py$ ./bin/python -v
    > Could not find platform independent libraries <prefix>
    > Could not find platform dependent libraries <exec_prefix>
    > Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
    > # installing zipimport hook
    > import zipimport # builtin
    > # installed zipimport hook
    > # zipimport: found 2509 names in /home/nima/py/lib/python26.zip
    > # zipimport: zlib UNAVAILABLE
    > 'import site' failed; traceback:
    > zipimport.ZipImportError: can't decompress data; zlib not available
    > # zipimport: zlib UNAVAILABLE
    >
    > Python 2.6.5 (r265:79063, May 17 2010, 18:36:54)
    > [GCC 4.4.3] on linux2
    > Type "help", "copyright", "credits" or "license" for more information.
    >>>> import sys
    >>>> sys.path

    > ['', '/home/nima/py/lib/python26.zip', '/home/nima/py/lib/python2.6/',
    > '/home/nima/py/lib/python2.6/plat-linux2', '/home/nima/py/lib/
    > python2.6/lib-tk', '/home/nima/py/lib/python2.6/lib-old', '/home/nima/
    > py/lib/lib-dynload']
    >
    >
    > --
    > Yours sincerely,
    > Nima Mohammadi
     
    News123, May 19, 2010
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MS News
    Replies:
    2
    Views:
    359
    MS News
    Aug 1, 2003
  2. SUPER KOOL 223
    Replies:
    0
    Views:
    499
    SUPER KOOL 223
    Jul 29, 2003
  3. Ramza Brown
    Replies:
    3
    Views:
    286
    fred.dixon
    Aug 24, 2005
  4. Kenneth McDonald
    Replies:
    0
    Views:
    668
    Kenneth McDonald
    Dec 19, 2006
  5. Irmen de Jong
    Replies:
    0
    Views:
    665
    Irmen de Jong
    Jul 16, 2011
Loading...

Share This Page