Package: heel
export_on_save:
html:
toc: true
markdown:
toc: trueprint_background: truepython三方包打包2021年4月30日11:41:51目录python三方包打包目录一、参考资料1.1 文档地址：https://packaging.python.org/tutorials/packaging-projects/二、环境2.1 python2.2 pip2.3 setuptools 和 wheel2.5 build2.4 twine三、准备3.1 创建项目3.1.1 项目目录3.1.2 创建pyproject.toml3.1.3 配置元数据3.1.4 创建一个许可证四、生成分布档案五、上传分布档案一、参考资料1.1 文档地址：https://packaging.python.org/tutorials/packaging-projects/二、环境2.1 python作用：python基本环境，确认所用版本，打包后使用时，注意python版本2.2 pip作用：安装包用的工具用法：pip install package_name2.3 setuptools 和 wheel作用：打包用的工具2.5 build作用：编译打包工具2.4 twine作用：上传包到官网三方库中三、准备3.1 创建项目3.1.1 项目目录目录结构packaging_tutorial/
├── LICENSE
├── pyproject.toml
├── README.md
├── setup.cfg
├── setup.py  # optional, needed to make editable pip installs work
├── src/
│   └── example_pkg/
│       └──init.py
└── tests/tests/是单元测试文件的占位符。现在将其留空。3.1.2 创建pyproject.tomlpyproject.toml是告诉构建工具（例如pip10+和 build）的文件，您正在使用的系统以及构建所需的系统。[build-system]
requires = [

    "setuptools>=42",
    "wheel"

]
build-backend = "setuptools.build_meta"3.1.3 配置元数据静态元数据（setup.cfg）：每次都保证相同。这更简单，更易于阅读，并且避免了许多常见错误，例如编码错误。[metadata]# replace with your username:name=heelversion=0.0.1author=Example Authorauthor_email=author@example.comdescription=A small example packagelong_description=file: README.mdlong_description_content_type=text/markdownurl=https://github.com/pypa/sampleprojectproject_urls=Bug Tracker=https://github.com/pypa/sampleproject/issuesclassifiers=Programming Language:: Python :: 3License:: OSI Approved :: MIT LicenseOperating System:: OS Independent[options]package_dir==srcpackages=find:python_requires=>=3.6[options.packages.find]where=src动态元数据（setup.py）：可能不确定。任何动态的或在安装时确定的项目，以及扩展模块或setuptools的扩展，都需要输入setup.py。importsetuptoolswithopen("README.md","r",encoding="utf-8")asfh:long_description=fh.read()setuptools.setup(name="heel",# Replace with your own usernameversion="1.0.0",author="秦",author_email="571169713@qq.com",description="这是一个测试打包上传的包！",long_description=long_description,long_description_content_type="text/markdown",url="https://github.com/qcdh1234/python",project_urls={"Bug Tracker":"https://github.com/qcdh1234/python/tree/master/pack_test_lib",},classifiers=["Programming Language :: Python :: 3","License :: OSI Approved :: MIT License","Operating System :: OS Independent",],package_dir={"":"src"},packages=setuptools.find_packages(where="src"),python_requires=">=3.6",)01. name是您的软件包的分发名称。

02. version是软件包版本。

03. author并author_email用于标识软件包的作者。

04. description 是该软件包的简短，一句话摘要。

05. long_description是该程序包的详细说明。

06. long_description_content_type告诉索引长描述使用什么类型的标记。

07. url是项目主页的URL。

08. project_urls可让您列出要在PyPI上显示的任意数量的额外链接。

09. classifiers给出了指数和点子你的包一些额外的元数据。

10. package_dir是一本字典，其中包名用于键，目录则用于值。

11. packages是应该包含在分发包中的所有Python导入包的列表。

12. python_requires提供了项目支持的Python版本。3.1.4 创建一个许可证请参阅https://choosealicense.com/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.四、生成分布档案安装build: python -m pip install --upgrade build进入setup.py所在目录中，编译：python -m build五、上传分布档案安装上传工具: python -m pip install --user --upgrade twine上传目标: python -m twine upload dist/*用户名：qcdh1234密码：qcdh1234.,12