目录
第一步:了解目录结构
目录结构如下,需要自己构建12345文件。
文件1:.pypirc
[distutils]
index-servers =
pypi
pypitest
[pypi] #这里的[]内容需要和上面保持一致,并且后续的命令也需要注意写对
repository: https://upload.pypi.org/legacy/ #正式地址
username = __token__
password = pypi-xxxxxx
[pypitest] #这里的[]内容需要和上面保持一致,并且后续的命令也需要注意写对
repository: https://test.pypi.org/legacy/ #测试地址
username = __token__
password = pypi-xxxxxx
ps:因为我上传测试地址时老报错,索性就不用了,直接用的正式地址上传。
文件2:LICENSE
MIT License
Copyright (c) 2022 pdudo
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:.py 自己写python代码 可以写一个简单的return,比如:
文件4:README.md(这个是markdown格式,可以从网上下一个)
# learning
文件5:setup.py
from setuptools import setup, find_packages
setup(
name='AAAAAAAAAAAAA', #自己填
version='0.0.4', #自己填
description='随便写点', #自己填
license='=License',
install_requires=[],
packages=[' AAAAAAAAAAAAA'], # 要打包的项目文件夹
include_package_data=True, # 自动打包文件夹内所有数据
author=' XXXXX', #自己填
author_email='XXXXXX@qq.com', #自己填
url='https://github.com/XXXX', #自己填
)
第二部分:命令行构建发布
#第一次上传用这个
python3 -m build
python3 -m twine upload --repository pypi dist/* --verbose
#如果有修改版本内容 比如删除掉了某个版本,用如下命令
python3 -m twine upload --repository pypi --verbose --skip-existing dist/*
第三部分:实操
1、build:
2、twine:
如果有文件存在报错,使用命令如下:
3、找到自己项目上传地址:Search results · PyPI
4、如何使用自己的库
import Mytestdemo #脚本名称
a = Mytestdemo.add(2, 4) #脚本名称.函数