注册账号 https://pypi.python.org/

目录结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package
|
+-- LICENSE
|
+-- README.txt
|
+-- setup.py
|
+-- package
. |
. +-- __init__.py
. |
. +-- pyscript_01.py
. |
. +-- pyscript_02.py
. |
. +-- pyscript_more.py
. |
.

setup.py模板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
# -*- coding: utf-8 -*-

try:
from setuptools import setup, find_packages
except ImportError:
import ez_setup
ez_setup.use_setuptools()
from setuptools import setup, find_packages

import os

from package import __version__

setup(
name = "package name",
version = __version__,
url = "",
packages = find_packages(),
include_package_data = True,
install_requires = [''],
keywords = "",
author = "",
author_email = "",
description = "",
license = "MIT",
classifiers = [
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
]
)

__init__.py模板

1
2
3
4
from package import function_01, function_02, function_more

__version__ = '0.1'
__all__ = ['function_01', 'function_02', 'function_more']

注册并发布到PyPI上

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$ python setup.py register sdist upload
# 会提示输入账号密码之类的巴拉巴拉..
running check
We need to know who you are, so please choose either:
1. use your existing login,
2. register as a new user,
3. have the server generate a new password for you (and email it to you), or
4. quit
Your selection [default 1]:
1
Username: ooxx
Password:
Registering pys-filelock to https://pypi.python.org/pypi
Server response (200): OK

# 可以保存账号信息,下次再提交可以不带register参数
I can store your PyPI login so future submissions will be faster.
(the login will be stored in C:\Users\ooxx\.pypirc)
Save your login (y/N)?y
running sdist

最后就可以使用easy_install或者pip安装包了