pip install wheel
pip install twine # 用来上传项目到PyPI
两个主要的功能:
python setup.py --help-commands
列出所有命令包含setup.py
命令的默认选项。例如:
[bdist_wheel]
# This flag says that the code is written to work on both Python 2 and Python
# 3. If at all possible, it is good practice to do this. If you cannot, you
# will need to generate wheels for each Python version that you support
universal=1
reStructureText写的README内容
当你需要一些附加文件的时候,而在python setup.py sdist
(或者 bdist_wheel)不会自动包含时。例如:
include *.txt
recursive-include examples *.txt *.py
prune examples/sample?/build
包
name='sample',
名称
version='1.2.0',
版本,参考:
1.2.0.dev1 # Development release
1.2.0a1 # Alpha Release
1.2.0b1 # Beta Release
1.2.0rc1 # RC Release
1.2.0 # Final Release
1.2.0.post1 # Post Release
description='A sample Python project',
long_description=long_description,
长短介绍
url='https://github.com/pypa/sampleproject',
主页
author='The Python Packaging Authority',
author_email='[email protected]',
作者信息
license='MIT',
classifiers=[
# How mature is this project? Common values are
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
'Development Status :: 3 - Alpha',
# Indicate who your project is intended for
'Intended Audience :: Developers',
'Topic :: Software Development :: Build Tools',
# Pick your license as you wish (should match "license" above)
'License :: OSI Approved :: MIT License',
# Specify the Python versions you support here. In particular, ensure
# that you indicate whether you support Python 2, Python 3 or both.
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
],
分类信息
keywords='sample setuptools development',
关键字
packages=find_packages(exclude=['contrib', 'docs', 'tests*']),
项目需要包含的包目录,可以手动指名,使用setuptools.find_packages
可以自动发现,使用exclude
关键字指名需要排除的目录
install_requires=['peppercorn'],
依赖包,使用pip时会自动解决依赖
package_data={
'sample': ['package_data.dat'],
},
经常需要附加文件的包中。这些可能是包相关数据,或者文档。统一称为为"package data"
必须相对路径
data_files=[('my_data', ['data/data_file'])],
如果你想将data files放在包外。
成对(目录,文件s)序列指名要安装的文件到目录中。如果目录是相对目录通常是:
>>> import sys
>>> sys.prefix
'/usr'
帮你构造安装后的可以调用脚本
entry_points={
...
},
定义plugins
注册脚本接口
建议使用开发模式进行测试
python setup.py develop
或者使用pip打包
pip install -e .
python setup.py sdist
python setup.py bdist_wheel --universal
python setup.py bdist_wheel
不同时支持2和3,你可能需要借用2to3,然后运行两次setup.py bdist_wheel
python setup.py bdist_wheel
python setup.py register
注册如果是PyPI网站注册的,还需要建立~/.pypirc
文件
[distutils]
index-servers=pypi
[pypi]
repository = https://pypi.python.org/pypi
username = <username>
password = <password>
也可以不指名密码,在执行时使用-p PASSWORD指名