+++
title = "Python打包和上传到pypi"
description = ""
date = 2023-02-18T21:59:09+08:00
featured = false
comment = true
toc = true
reward = true
categories = [
""
]
tags = [
"python"
]
series = []
images = []
+++
教程
用 python 的人都用 pip 安装过包。那么有着开源精神的你,是否也想把自己写的包上传到 pypi 呢?
更新/发布步骤:
- 修改完善
setup.py
- 进行本地测试
python setup.py develop
- 编译
python3 setup.py sdist
- 上传到 pypi
twine upload dist/*
新手注意事项
你需要先去 pypi 注册一个账号,给你的包起一个名字(搜一搜没有被占用就行),然后用 pip 在本地安装 twine,这个是用来上传到 pypi 的工具。
目录结构需要注意,你的项目目录结构应该是这样的,要把 setup.py 放在外面:
setup.py 的内容大致如下;可以抄我的,改改名称
、版本
、描述
就行,非常简单。
import codecs
import os
from setuptools import setup, find_packages
# these things are needed for the README.md show on pypi (if you dont need delete it)
here = os.path.abspath(os.path.dirname(__file__))
with codecs.open(os.path.join(here, "README.md"), encoding="utf-8") as fh:
long_description = "\n" + fh.read()
# you need to change all these
VERSION = '1.0.2'
DESCRIPTION = 'a ligh weight menu , support both win and mac '
LONG_DESCRIPTION = 'dumb_menu is a ligh weight menu ,support hot key, support both win and mac'
setup(
name="dumb_menu",
version=VERSION,
author="clever chen",
author_email="",
description=DESCRIPTION,
long_description_content_type="text/markdown",
long_description=long_description,
packages=find_packages(),
install_requires=[],
keywords=['python', 'menu', 'dumb_menu','windows','mac','linux'],
classifiers=[
"Development Status :: 1 - Planning",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3",
"Operating System :: Unix",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
]
)
编译成功的话会生成 dist 和 egg-info 两个文件夹,egg-info 是用来记录包的信息的,dist 是用来存放打包好的包的。
然后就可以上传到 pypi 了,最好测试好了再发,因为你不能发重复的版本号。
twine upload dist/*
然后后面再修改和更新的话,参考 更新/发布步骤 即可。
标签:02,description,python,18,setup,py,pypi,menu From: https://www.cnblogs.com/kasusa/p/17752921.html