网站信息安全监测建设方案重庆专题片制作
网站信息安全监测建设方案,重庆专题片制作,网站页脚内容,网站开发的发展1. 整理包结构
myfirstpkg/ # 项目根目录#xff08;名字任意#xff09;
├── myfirstpkg/ # 核心包目录#xff08;必须和包名一致#xff09;
│ ├── __init__.py # 包标识文件#xff08;必填#xff09;
│ └──…1. 整理包结构myfirstpkg/ # 项目根目录名字任意 ├── myfirstpkg/ # 核心包目录必须和包名一致 │ ├── __init__.py # 包标识文件必填 │ └── core.py # 你的核心代码 ├── README.md # 说明文档必填告诉用户怎么用 ├── LICENSE # 开源许可证必填如 MIT ├── pyproject.toml # 构建配置必填新版标准 └── setup.cfg # 包信息配置可选各文件说明1.myfirstpkg/core.py放你的核心代码比如def hello(): return Hello! 这是我发布的第一个PyPi包~2.myfirstpkg/__init__.py导出接口方便用户使用from .core import hello # 把hello函数暴露出去 __version__0.0.3 # 版本号必填3.README.md简单写使用说明比如# myfirstpkg 一个简单的 Python 测试包 # 安装 pip install myfirstpkg # 使用 from myfirstpkg import hello print(hello())4.LICENSE推荐用 MIT 许可证复制 MIT 文本即可网上搜「MIT LICENSE」直接复制:MIT License Copyright (c) [2026] [tongxiaobin/Ethan] 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.2. 配置构建文件pyproject.toml这是新版 Python 发布的核心配置文件# pyproject.toml [build-system] requires [setuptools61.0, wheel] build-backend setuptools.build_meta3. 配置包信息setup.cfg注意不要有注释version与__init__.py中的version一致[metadata] name myfirstpkg_txb version 0.0.3 author tongxiaobin author_email 1344184686qq.com description 一个测试用的 Python 包 long_description file: README.md long_description_content_type text/markdown url https://github.com/tongxiaobin/myfirstpkg classifiers Programming Language :: Python :: 3 License :: OSI Approved :: MIT License Operating System :: OS Independent [options] packages find: python_requires 3.64. 安装构建工具发布前需要安装两个工具build构建包和twine上传到PyPI:pip install build twine5. 构建包在项目根目录执行命令生成可发布的包文件.whl和.tar.gzpython -m build执行后会在根目录生成dist/文件夹里面是你的包文件dist/ ├── myfirstpkg-0.0.1-py3-none-any.whl # 轮子包推荐 └── myfirstpkg-0.0.1.tar.gz # 源码包6. 上传到PyPI一. 注册PyPi账号先去PyPI官网注册账号记住用户名和密码以及API Token现在上传都是通过Token。二. 上传包用twine上传比直接上传更安全。twine upload dist/*执行后会提示输入PyPI的用户名和密码现在都是提示输入API Token输入完等到上传即可。API Token获取步骤用户名—Account seetings—Add API token只出现一次保存好三. 验证发布结果上传成功后其他人就可以通过pip安装你的包了pip install myfirstpkg_txbimport myfirstpkg print(myfirstpkg.__version__) 0.0.3 # 可直接调接口因为在__init__.py里已经执行了from .core import hello myfirstpkg.hello() Hello! 这是我发布的第一个PyPi包~ # 也可通过core模块调用 from myfirstpkg import core core.hello() Hello! 这是我发布的第一个PyPi包~四. 注意事项包名唯一性PyPi上的包名是全局唯一的如果提示“包名已存在”需修改setup.cfg里的name版本号规则每次更新发布必须换版本号如0.0.1—0.0.2可在PyPI官网用户名—Your projects里管理已经上传的项目如果旧项目删除了重新上传也必须换版本号