pip包制作
项目文件夹
如下配置
modulename
├── LICENSE # 声明,给模块使用者看,说白了就是使用者是否可以免费用于商业用途等。
├── README.md # 模块介绍
├── demos # 使用案例
├── modules # 模块代码目录
│ └── __init__.py
└── setup.py # 给setuptools提供信息的脚本(名称、版本等)
LICENSE文件就是咱们模块的许可证,给模块使用者看,说白了就是使用者是否可以免费用于商业用途等。一般开源的软件会选择相对宽泛许可证 MIT,即:作者保留版权,无其他任何限制。
Copyright (c) 2018 The Python Packaging Authority
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
readme就是对当面模块的描述信息,一般为MD格式
demos目录通常写模块的使用示例
setup.py相当于一个配置文件
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="modulename", # 模块名称
version="1.0", # 当前版本
author="xxx", # 作者
author_email="xxx@l63.com", # 作者邮箱
description="一个非常xx的包", # 模块简介
long_description=long_description, # 模块详细介绍
long_description_content_type="text/markdown", # 模块详细介绍格式
# url="https://github.com/xxx/xx", # 模块github地址
packages=setuptools.find_packages(), # 自动找到项目中导入的模块
# 模块相关的元数据
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
# 依赖模块
install_requires=[
'pillow',
],
python_requires='>=3',
)
modules模块目录,下面写对应的模块及方法
代码打包上传
需安装setuptools和wheel两个包
python -m pip install --upgrade setuptools wheel
打包代码
pip setup.py sdist bdist_wheel
发布模块 pipy.org需注册
安装twine包
pythpn -m pip install --upgrade twine
发布
python -m twine upload --repository-url https://upload.pypi.org/xxx/ dist/*
上传时需输入pipy的用户名和密码
pip包制作
http://www.jcwit.com/article/135/