在项目目录执行下面的操作:
配置文件:
import io
import os
from setuptools import setup, find_packages
with io.open(os.path.join("docs", 'index.rst'), encoding='utf-8') as f:
readme = f.read()
with io.open('requirements.txt') as f:
requirements = f.readlines()
setup(
name="xxx",
version="0.0.1",
url='https://github.com/',
author='James',
author_email='xxx@xxx.com',
maintainer='James',
maintainer_email='xxx@xxx.com',
description='xxx',
long_description=readme,
license="MIT",
packages=find_packages(),
classifiers=[
'Development Status :: 5 - Production/Stable',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Topic :: Database',
],
install_requires=requirements,
)
requirements.txt 填写依赖关系.
docs/index.rst 填写文档
检查:
python setup.py check
输出一般是running check
如果有错误或者警告,就会在此之后显示
没有任何显示表示Distutils认可你这个setup.py文件。
打包为源码包:
python setup.py sdist build
上传生成的包:
可以使用setuptools,或者twine上传,推荐使用twine上次,因为使用setuptools上传时,你的用户名和密码是明文或者未加密传输,安全起见还是使用twine吧
python setup.py sdist upload
使用twine上传,先安装twine
pip install twine
twine upload dist/*
文件包含的设置:
新建文件MANIFEST.in,常用的如下:
recursive-include docs * include LICENSE
第一行 recursive-include 表示递归包含 docs 目录下的所有
第二行 include 表示包含 LICENSE 这一个文件
错误提示:
出现
HTTPError: 400 Client Error: File already exists. See https://upload.pypi.org/help/#file-name-reuse for url: https://upload.pypi.org/legacy/
请清理掉 build 和 dist 目录