Python Eggs

This is a summary of the content from network.

1) What is Python egg file ?
It’s simply a way of distributing Python packages, similar to RPM or Java jar package.

2) Where do I find the Python eggs ?
You can find Python eggs on quite a few places on the web, e.g. at a package author’s website. The biggest repository of eggs is the Cheeseshop (or PyPI) though), an index for Python packages.

3) How do I install the egg files ?
In order to be able to install eggs you simply need to install easy_install which is easily done by downloading ez_install.py (you candownload it here).
Once you have done this you can simply install an egg by calling:
easy_install somepackage.egg

You can also give a URL to an egg and use
easy_install http://somehost.somedomain.com/somepackage.egg

Note: If an egg is not found at that location or in the directory you give, easy_install will automatically query the Cheeseshop for the egg location.

4) How to create our own Python eggs ?

  1. Install setuptools (Ubuntu/Debian)
    sudo apt-get install python-setuptools
    There are two manual ways to install it
    • $ wget http://peak.telecommunity.com/dist/ez_setup.py
      $ sudo python ez_setup.py
      Update setuptools:
      $ sudo python ez_setup.py -U setuptools
    • $ wget http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg
      $ sudo sh setuptools-0.6c11-py2.6.egg
  2. Create egg files (example)
    • The following is the directory structure
      README
      eventlet
      examples
      setup.py
    • The setup.py now looks like as the following. From the setup.py, we can see we define some meta information for the eventlet package

      #!/usr/bin/env python
      from distutils.core import setup
      setup(
          name='eventlet',
          version='0.1',
          description='Coroutine-based networking library',
          author='Linden Lab',
          author_email='sldev@lists.secondlife.com',
          url='http://wiki.secondlife.com/wiki/Eventlet',
          packages=['eventlet'])

    • Now so far it’s great but we might miss some features of eggs here, namely the ability to package it as one file, to register it with the cheeseshop and to define dependencies. So to add this we have to do just a few changes to setup.py. (So we added those classifiers to put it into the right categories on Cheeseshop and most importantly we added the requirement “greenlet”. If you then install the egg setuptools will automatically install greenlet as well.)
      #!/usr/bin/env python
      from distutils.core import setup
      setup(
          name='eventlet',
          version='0.1',
          description='Coroutine-based networking library',
          author='Linden Lab',
          author_email='sldev@lists.secondlife.com',
          url='http://wiki.secondlife.com/wiki/Eventlet',
          packages=['eventlet'],
          long_description="""\
            eventlet is a coroutines-based network library for python ...
            """,
          classifiers=[
                "License :: OSI Approved :: GNU General Public License (GPL)",
                "Programming Language :: Python",
                "Development Status :: 4 - Beta",
                "Intended Audience :: Developers",
                "Topic :: Internet",
            ],
          keywords='networking eventlet nonblocking internet',
          license='GPL',
          install_requires=[
              'setuptools',
              'greenlet',
            ],
          )
    • Create an egg by calling the following command. (This will create an egg distribution file which you can find indist/eventlet-0.1-py2.4.egg (if you used Python 2.4)
      python setup.py bdist_egg
    • You can check the contents by calling unzip -t eventlet-0.1-py2.4.egg and as you can see it’s basically the contents of the eventlet directory plus an EGG_INFO directory with metadata. Also included are the .pyc files as it’s a binary distribution.
5) The other way to create egg file by using paster (Python Paste)
What we are interested in is especially paste.script which is some sort of template based automation system.
  1. Install PasteScript
    easy_install -U PasteScript
  2. Now that PasteScript is installed you can list the available templates:
      $ paster create --list-templates
      Available templates:
      archetype:          A Plone project that uses Archetypes
      basic_namespace:    A project with a namespace package
      basic_package:      A basic setuptools-enabled package
      basic_zope:         A Zope project
      nested_namespace:   A project with two nested namespaces.
      paste_deploy:       A web application deployed through paste.deploy
      plone:              A Plone project
      plone2.5_buildout:  A buildout for Plone 2.5 projects
      plone2.5_theme:     A Theme for Plone 2.5
      plone2_theme:       A Theme Product for Plone 2.1 & Plone 2.5
      plone3_buildout:    A buildout for Plone 3 projects
      plone3_portlet:     A Plone 3 portlet
      plone3_theme:       A Theme for Plone 3.0
      plone_app:          A Plone App project
      plone_hosting:      Plone hosting: buildout with ZEO and any Plone version
      tgbase:             tg base template
      tgbig:              For more complex projects
      tgwidget:           TurboGears widget projects
      turbogears:         web framework

    (I have Turbogears installed as well which is why here are more templates listed than you have)

  3. The interesting ones for Python are basic_package and basic_namespace. We will usebasic_package for now as it creates a package ready for egg distribution.
    paster create -t basic_package
    and it will ask us a lot of questions, basically all the metadata we have to put into the setup.py file. After it’s finished you should have a new directory with a basic egg supporting structure.

6) How to uninstall the egg file ?

  1. Enter the directory where the egg file installed
    $ cd /usr/local/lib/python2.6/dist-packages
    $ cat easy-install.pth | grep eventlet
    ./eventlet-0.1.0-py2.6.egg
    $ ls -F|grep eventlet
    eventlet-0.1.0-py2.6.egg/
  2. delete 'eventlet' from easy-install.pth and then delete the eventlet-0.1.0-py2.6.egg directory

Reference:
http://mrtopf.de/blog/en/a-small-introduction-to-python-eggs/
http://www.worldhello.net/2010/12/08/2178.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值