都是在hello目錄下新建setup.py的文件。python
distutils雖然在python的標準庫中,可是已經中止開發了,setuptools提供向distutils的兼容,而且有一些有用的,有效率的命令。linux
經常使用的setuptools打包命令有:git
python setup.py sdist
python setup.py bdist_wininst
python setup.py bdist_rpm
python setup.py bdist
python setup.py bdist_wheel
使用distutilswindows
例子:服務器
from distutils.core import setup setup(name="hgf", version="0.1", description="brief introduce", author="hgf", author_email="hgf@a.com", packages=['hello'] )
說明:測試
name
,author
,version
,url
使用setuptoolsui
例子:this
import setuptools setuptools.setup( name="hello", version="0.1", author="hgf", author_email="hgfgood@gmail.com", description="this is a hello test about setuptools", license="GPL", package=["test"], entry_point={ "consol_script":[ "sayhello = test.hello:say_hello" ] } )
說明,能夠不用entry_pointurl
pbr在setuptools
的基礎上作了一些改進:code
requirements.txt
的自動依賴安裝sphinx
實現文檔自動化authors
和 ChangeLog
setup.cfg
文件裏面pbr的打包例子:
setup.py
:
import setuptools setuptools.setup(setup_requires=['pbr'],pbr=True)
setup.cfg
[metadata] name=hello author=hgf author_email=hgfdodo@gmail.com licens=MIT description-file=README.rst requires-python= >=2.6 classifier= Development Status :: 4 - Beta Environment :: Console Intended Audience :: Developers Intended Audience :: Information Technology license ::OSI Approved :: Apache Software license Operating System :: Os Independent Programming Lauguage :: python [files] packages = test
注意:使用pbr打包,源程序必定要使用git,而且源碼的根目錄下必定要有 **
README.rst
** 文件
https://testpypi.python.org/pypi
上註冊一個本身的賬號~/.pypi
中加入做者信息 [distutils] index-server = pypi testpypi [pypi] username = hgfgood password = password [testpypi] username = hgfgood password = password repository = https://testpypi.python.org/pypi
說明: 1. 設置索引服務器 2. 分別寫索引服務器的用戶名密碼 3. testpypi是測試服務器
在pypi的索引中註冊本身的項目 python setup.py register -r hello
上傳分發代碼 python setup.py sdist upload -r hello
(tar源碼版) python setup.py bdist_wheel upload -r hello
(wheel版)