当前位置: 首页 > article >正文

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/

在这里插入图片描述


http://www.kler.cn/a/6007.html

相关文章:

  • 递归构建树菜单节点
  • STM32+WIFI获取网络时间+8位数码管显示+0.96OLED显
  • DAY15 神经网络的参数和变量
  • Linux(上):基本知识篇
  • Flutter:封装一个自用的bottom_picker选择器
  • 掌握正则表达式:从入门到精通的实战指南
  • 自己动手写CPU——第一篇
  • ChatGPT AI国内免魔法使用
  • 命令行上的数据科学第二版 二、开始
  • VUE从0开始,一个小时就学完VUE
  • Linux系统之diff命令的基本使用
  • 数据结构-堆-堆排序-TopK
  • 05_Python学习基础
  • 蓝桥杯刷题第二十五天
  • 玩转肺癌目标检测数据集Lung-PET-CT-Dx ——②预览数据集,绘制锚框
  • FastDFS单节点搭建
  • Linux安装JDK教程(图文详解,一步搞定)
  • https
  • 对象的构造及初始化
  • 【MATLAB点云处理】计算FPFH并可视化
  • process.spider_loader.list()为空列表是什么原因导致的?KeyError: ‘Spider not found
  • C#基本语法和数据类型
  • 慕了,这些地区软考没过45分居然也能拿证?
  • 浅谈JVM(四):运行时数据区
  • 【竞赛经历】CSDN第40期竞赛题解
  • 年薪50W京东软件测试工程师的成长路 —— 我们都曾一样迷茫