使用pip发布python程序

本文详细介绍如何在PyPI上注册账号并上传Python项目。包括创建符合规范的setup.py文件,使用Twine工具上传软件包,以及如何验证上传是否成功。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.注册账号

首先在https://pypi.org 网站上注册账号

2.创建要上传的文件

代码结构

其中的几个文件

setup.py,需要通过这个文件进行 Python 代码的编译(可能会有依赖的其他代码包或者依赖的 C 文件)和安装。

import setuptools

with open("README.md","r") as fh:
	long_descritiption = fh.read()
	

setuptools.setup(
	name='wyb',
	version='0.0.1',
	author='wyb',
	author_email='1770841968@qq.com',
	description="pip install test",
	long_descritiption=long_descritiption,
	long_descritiption_content_type='text/markdown',
	url='https://github.com/wengyinbing/Rangomaster',
	packages=setuptools.find_packages(),
	classifiers=(
        "License :: OSI Approved :: MIT License",
        "Intended Audience :: Developers",
        "Operating System :: OS Independent",
        "Programming Language :: Python",
        "Programming Language :: Python :: 2",
        "Programming Language :: Python :: 2.6",
        "Programming Language :: Python :: 2.7",
        "Programming Language :: Python :: 3",
        "Programming Language :: Python :: 3.3",
        "Programming Language :: Python :: 3.4",
        "Programming Language :: Python :: 3.5"
    ),
)

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:这个是软件行业的惯例了,帮助文档。

#wyb
对模块的进一步吹牛

wyb/__init__.py

from __future__ import absolute_import
from .wyb import *

name = "wyb"

wyb/wyb.py

def output():
	print("wyb")

3.上传

在文件目录下执行

python setup.py sdist bdist_wheel

执行之后的文件目录是

上传

twine upload dist/*

实际上我输入的命令是

 C:\Users\Administrator\AppData\Roaming\Python\Python36\site-packages\twine\__main__.py upload dist/*

最后测试下载

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值