在PyPI上发包

526 阅读1分钟

第一步: 安装基础工具

pip install setuptools wheel --upgrade

pip install twine

第二步: 注册

pypi.org/

第三步: 准备项目目录

目录结构

/某某目录
    README.rst
    setup.py
    requirements.txt (可选)
    test-requirements.txt (可选)
    你的包/
        __init__.py
        你的文件.py

文件内容: setup.py

#!/usr/bin/env python
# coding=utf-8

from distutils.core import setup
from setuptools import find_packages

setup(
    name='t3tools',
    version='0.0.6',
    description=(
        '实用工具 from 唐峰2098'
    ),
    long_description=open('README.rst').read(),
    author='唐峰',
    author_email='tangfeng2098@outlook.com',
    maintainer='唐峰',
    maintainer_email='tangfeng2098@outlook.com',
    license='MIT License',
    packages=find_packages(),
    # packages=['common'],
    platforms=["all"],
    url='http://null.null.null',
    classifiers=[
        'Intended Audience :: Developers',
        'Operating System :: OS Independent',
        'Natural Language :: Chinese (Simplified)',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: 3.7',
        'Programming Language :: Python :: 3.8',
        'Topic :: Software Development :: Libraries'
    ],
)

第四步: 构建

python setup.py sdist build
或
python setup.py bdist_wheel --universal

完成后会多出几个目录:

build/
dist/
你的包名.egg-info/

第五步: 发布

twine upload dist/*

输入用户名/密码, 成功!

第六步: 检查

方式1. 到pypi网站检查: pypi.org/

方式2. 直接安装

pip install 你的包

参考

www.cnblogs.com/jinjiangong…

end