Python 自建项目上传到 PyPI 之后通过 pip 可安装
Python 自建项目上传到 PyPI 之后通过 pip 可安装
- 1. 登录 PyPI 网站
- 2. 创建一个 Python 项目
- 3. 文件信息
- LICENSE
- MANIFEST.in
- pyproject.toml
- README.md
- requirements.txt
- 4. 上传到 PyPI 上
- 5. 查看
1. 登录 PyPI 网站
官方网站: https://pypi.org/
注册登录后可以进行查看文档: https://packaging.python.org/en/latest/tutorials/installing-packages/
2. 创建一个 Python 项目
下面红框中的文件是必须要有的
其中 ykenan_log 是自定义的项目的内容
3. 文件信息
LICENSE
授权文件,内容类似于下面这种
Copyright (c) 2023 YKenan
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.
MANIFEST.in
MANIFEST.in 文件由命令组成,每行一个,指示 setuptools 从 sdist 中添加或删除一些文件集。
详细内容:https://packaging.python.org/en/latest/guides/using-manifest-in/?highlight=MANIFEST.in#manifest-in-commands
类似下面的内容
include requirements.txt
include README.md
include pyproject.toml
pyproject.toml
核心文件
详细链接:https://packaging.python.org/en/latest/specifications/declaring-project-metadata/#declaring-project-metadata
[build-system]
requires = ["setuptools>=42", "coloredlogs>=15.0"]
build-backend = "setuptools.build_meta"
[project]
name = "ykenan_log"
version = "0.2.0"
authors = [
{ name = "Name", email = "xxxxxxx@qq.com" },
]
keywords = ["ykenan", "log", "file"]
description = "Log information: Print the log, export the log file."
readme = "README.md"
requires-python = ">=3.7"
dependencies = ["coloredlogs>=15.0"]
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
[project.urls]
github = "https://github.com/YuZhengM/ykenan_log"
dependencies: 代表着当 pip 加载这个包的时候回自动加载这个依赖包。其中需要将这个内容与 requirements.txt requirements.txt 文件结合。
version: 每次上传的时候版本不能一样。
README.md
帮助文档信息
# ykenan_file
> **`File read and write operations`**
This is a simple log package. You can see
[Github-ykenan_file](https://github.com/YuZhengM/ykenan_file)
[PyPI-ykenan_file](https://pypi.org/project/ykenan-file/)
## Use
> install
pip install ykenan_file
requirements.txt
用到的依赖包情况
ykenan-log>=0.2.0
pandas>=1.5.3
4. 上传到 PyPI 上
打包会生成 dist 和 xxx.egg-info 文件夹
py -m build
检查内容
twine check dist/*
上传信息
twine upload dist/*
每次打包的时候最好删除 dist 和 xxx.egg-info 文件夹
5. 查看
https://pypi.org/project/ykenan-log/