注册账号

创建.pypirc文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
[distutils]
index-servers =
  pypi
  pypitest

[pypi]
repository=https://upload.pypi.org/legacy/
username=your_username
password=your_password

[pypitest]
repository=https://test.pypi.org/legacy/
username=your_username
password=your_password

保存到~/.pypirc

1
chmod 600 ~/.pypirc

准备工作

工作目录结构

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
root-dir/   # arbitrary working directory name
  setup.py
  setup.cfg
  LICENSE.txt
  README.md
  protoss-pypi/
    __init__.py
    foo.py
    bar.py
    baz.py

setup.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
from distutils.core import setup
setup(
    name='protoss-pypi',
    packages=['protoss-pypi'],
    version='0.1.1',
    description='A random test lib',
    author='hbprotoss',
    author_email='gamespy1991@gmail.com',
    url='https://github.com/hbprotoss/pypitest',
    download_url='https://github.com/hbprotoss/pypitest/archive/master.zip',
    keywords=['testing', 'logging', 'example'],  # arbitrary keywords
    classifiers=[],
)

name和packages保持一致,url写git仓库地址,download_url写源码包地址

setup.cfg

markdown写的readme文件需要显示指定

1
2
[metadata]
description-file = README.md

打包上传

正式

1
python setup.py sdist upload -r pypi

测试

1
python setup.py sdist upload -r pypitest

参考资料:

http://peterdowns.com/posts/first-time-with-pypi.html