Python 自建项目上传到 PyPI 之后通过 pip 可安装

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/

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值