python打包上传至pypi —— 具有多个目录的项目工程快速打包上传
程序员文章站
2022-03-29 22:48:23
...
项目目录
项目目录说明:
- cqrcode:项目包(我的里面有多个目录)
- LINCENSE:许可证
- MANIFEST.in:需要打包的项目文件说明
- README.md:项目说明文档
- requirements.txt:填写需要额外安装的第三方库文件
- setup.py:打包上传所需的必要文件
1. 项目包
由于项目需要调用 app、view 目录下的脚本,故相当于将 app、view 视作了模块,这两个目录中均存在 __init __.py 文件。
而项目 —— cqrcode 中所含有的 __init __.py 脚本不能省略(原因是需要作为模块标示),如下图所示:
2. LINCENSE
拷贝复制即可?
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.
3. MANIFEST.in
说明需要额外打包的目录。
include README.md
include LICENSE
include requirements.txt
recursive-include cqrcode/app *
recursive-include cqrcode/static *
recursive-include cqrcode/view *
4. README.md
5. requirements.txt
Pillow>=6.1.0
pyzbar>=0.1.8
qrcode>=6.1
PySnooper>=0.2.8
pretty-errors>=1.2.7
matplotlib>=3.0.3
6. setup.py
import setuptools
setuptools.setup(name='cqrcode',
version='0.14',
description='Generate a QR code that can adapt to the cylinder',
long_description=open('README.md', 'r', encoding='utf-8').read(),
author='xxx',
author_email='aaa@qq.com',
url = 'https://pypi.org/project/cqrcode/',
license='MIT', # 与之前你选用的许可证类型有关系
packages=setuptools.find_packages(),
zip_safe=False,
include_package_data=True,
install_requires = [
'Pillow>=6.1.0',
'pyzbar>=0.1.8',
'qrcode>=6.1',
'PySnooper>=0.2.8',
'pretty-errors>=1.2.7',
'matplotlib>=3.0.3',
],
keywords='cylinder qrcode',
classifiers=[
"Natural Language :: Chinese (Simplified)",
"Development Status :: 3 - Alpha",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"License :: OSI Approved :: MIT License",
"Topic :: Utilities"
],
)
6. 准备twine配置文件
该目录下:
新建该脚本:
内容为:
[distutils]
index-servers=pypi
[pypi]
repository = https://upload.pypi.org/legacy/
username: pypi 账户名
password: pypi 账户密码
至此,准备完毕。
准备上传
三条命令:
python setup.py check
python setup.py sdist bdist_wheel
twine upload dist/*
具体演示
- 先卸载已安装的 cqrcode
C:\Users\83735>pip uninstall cqrcode
Found existing installation: cqrcode 0.13
Uninstalling cqrcode-0.13:
Would remove:
d:\python35\lib\site-packages\cqrcode-0.13.dist-info\*
d:\python35\lib\site-packages\cqrcode\*
Would not remove (might be manually added):
d:\python35\lib\site-packages\cqrcode\static\0二维码填充效果.png
d:\python35\lib\site-packages\cqrcode\static\0二维码识别掩码.png
d:\python35\lib\site-packages\cqrcode\static\0二维码识别模板.png
d:\python35\lib\site-packages\cqrcode\static\0填充结果.png
d:\python35\lib\site-packages\cqrcode\static\0扩展图片.png
d:\python35\lib\site-packages\cqrcode\static\_input.txt
d:\python35\lib\site-packages\cqrcode\static\_白板.png
d:\python35\lib\site-packages\cqrcode\static\overall_.png
d:\python35\lib\site-packages\cqrcode\static\传统二维码.png
Proceed (y/n)? y
Successfully uninstalled cqrcode-0.13
-
准备打包,在该目录下,shift+右键 打开 Powershell。
-
运行命令 python setup.py check ,检查 setup.py 运行结果为 running check 则正确。
-
运行命令 python setup.py sdist bdist_wheel
生成一堆文件: -
检查 dist 目录,会产生两个文件
-
运行命令 twine upload dist/* 上传。
上传成功。 -
下载安装演示