Skip to content

Pypi and namespace packages

pkienzle edited this page May 25, 2011 · 2 revisions

After some struggle we got pypi and namespace packages to work.

First, a reminder how to use pypi once you've created your account

  1. create ~/.pypirc:

    [distutils]
    index-servers =
        pypi
    
    [pypi]
    username:yyyyy
    password:******
    
  2. create your namespace path. For example, if you want to import bar as foo.bar:

    $ mkdir foo
    $ cat >foo/__init__.py <<EOF
    from pkgutil import extend_path
    __path__ = extend_path(__path__, __name__)
    
  3. update setup.py to include namespaces:

    # so python setup.py sdist gets all the files
    if os.path.exists('MANIFEST'): os.unlink('MANIFEST')
    
    import foo.bar
    setup(...
          name='foo.bar',
          version=foo.bar.__version__
          package_dir={'foo.bar':'bar'},
          packages=['foo','foo.bar'],
          ...)
    

    See http://docs.python.org/distutils/setupscript.html#additional-meta-data

  4. register your package:

    $ python setup.py register
    
  5. upload your package:

    $ python setup.py sdist upload
    
  6. test your packages:

    $ virtualenv test --no-site-packages
    $ test/bin/pip install foo.bar
    $ test/bin/python
    
    >>> import foo.bar

When you find out you've uploaded your packages incorrectly, log on to you pypi account and delete the version (not just the file) that you just uploaded, fix the problem, and try again.

Clone this wiki locally