美文网首页
构建第三方python包

构建第三方python包

作者: SodaCrush | 来源:发表于2020-02-08 20:20 被阅读0次

参考自: https://www.jianshu.com/p/81fe5a5cd27a

准备工作

  • pypi官网注册账号
  • $home路径下新建.pypirc 并写入如下内容
[distutils]
index-servers = pypi

[pypi]
repository: https://upload.pypi.org/legacy/
username: user_name(非邮箱或手机)
password: pass_word
  • 环境(基于python3)
    python -m pip install --upgrade pip setuptools wheel
    尽量保证pip、setuptools、wheel是最新版本
    • pip
    • setuptools
    • wheel
    • twine

项目根路径下准备setup.py

import setuptools

# setup更多信息,请参考 https://packaging.python.org/guides/distributing-packages-using-setuptools/

with open("README.md", "r") as f:
    long_description = f.read()

setuptools.setup(
    name="hello-world",                                     # 包的分发名称
    version="0.0.1",                                        # 版本号,
    author="author",                                        # 作者
    author_email="author@example.com",                      # 邮箱
    description="Description info",                         # 包简介
    long_description=long_description,                      # 包的详情
    long_description_content_type="text/markdown",          # 加载格式
    url="https://xxx.com/",                                 # 项目地址
    packages=setuptools.find_packages(),                    # 搜索包
    classifiers=[                                           # 包的其他信息
        "Programming Language :: Python :: 3",              # 语言环境
        "License :: OSI Approved :: MIT License",           # MIT证书
        "Operating System :: OS Independent",               # 不区分操作系统
    ],
)

项目结构

-- project_name      # 项目名
    -- package_name         # 包名字
        -- __init__.py     # 一定要有init文件
        -- main.py
    -- .gitignore         
    -- README.md           # 文档
    -- setup.py            # 打包程序

生成源码包 tar.gz 或者 wheel

python setup.py sdist
# or
python setup.py sdist bdist_wheel

上传至pypi

python -m twine upload dist/*

相关文章

网友评论

      本文标题:构建第三方python包

      本文链接:https://www.haomeiwen.com/subject/tzxwxhtx.html