作者:松原电信曹玉威_203 | 来源:互联网 | 2023-08-04 17:36
这篇文章主要介绍了如何将自己的python库打包成wheel文件并上传到pypi,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着
新建项目
如下图,比如sigma目录是我要上传的项目,在six-sigma目录下新建三个文件,分别是LICENSE也就是开源协议,README.md文件,用于介绍自己的项目和setup.py这个配置文件,此文件配置关于项目和作者的一些信息,接下来我们一一介绍。
LICENSE文件
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文件
# Example Package
This is a simple example package. You can use
[Github-flavored Markdown](https://guides.github.com/features/mastering-markdown/)
to write your content.
setup.py文件
import setuptools
with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
setuptools.setup(
name="sigma_t", # 项目名称
version="0.0.1", # 项目版本信息
author="AlanRick", # 作者 写你的真实姓名即可
author_email="zs13128488417@gmail.com", # 作者邮箱
description="six sigma project", # 项目简介
long_description=long_description, # 项目详细的介绍 这里直接读取README.md文件
long_description_content_type="text/markdown", # 项目详细介绍的文件类型
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", # python所需要的版本
)
安装所需插件
确保您已经在pypi.org上注册了账号,然后执行以下命令
pip install wheel
pip install twine
打包文件为*.whl
首先在终端cd到setup.py文件所在目录下,并在终端执行以下命令进行打包
python setup.py bdist_wheel
打包完成生成如下文件
上传包至pypi
python -m twine upload dist/sigma-0.0.1-py3-none-any.whl
如下在终端提示您输入用户名和密码然后进行上传
如下上传成功
在pypi项目管理页面可以看到刚上传好的文件
点开项目可以看到我们的配置文件显示在前端了
结语
也可以参考pypi官网的方法进行上传。
到此这篇关于如何将自己的python库打包成wheel文件并上传到pypi的文章就介绍到这了,更多相关python库打包成wheel并上传到pypi内容请搜索编程笔记以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程笔记!