Python包的构建和发布

本文只讲述上传到test.pypi.org的流程。如果要上传到正式的pypi.org上,只需要注册一个正式的账号。一旦发布成功就可以使用pip install [your-package]的命令进行安装。

1、项目目录如下

protocol_package
└── huitu_iot_protocol_rule
    └── __init__.py
    └── xxx.py
└── README.md
└── setup.py

2、setup.py文件如下所示

# -*- coding: utf-8 -*-
"""
File Name  setup.py
Created on 2020/05/01
@author: gw
"""

from setuptools import setup

setup(
    name='huitu_iot_protocol_rule',  # 项目名称,保证它的唯一性,不要跟已存在的包名冲突即可
    version='1.0.0',  # 版本
    description='协议规约',  # 项目的简单描述
    author='gw',  # 作者
    author_email='[email protected]',    # 邮箱
    url='http://xx.xx.xx.xx:xxxx',  # 项目地址
    packages=['huitu_iot_protocol_rule'],
)

3、项目打包

python2.7 setup.py sdist bdist_wheel

4、上传至Test PyPI

python2.7 -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*

5、安装

5.1、在dist文件夹下用tar包安装

pip2.7 install huitu_iot_protocol_rule-1.0.0.tar.gz

5.2、从Test PyPI安装

pip2.7 install -i https://test.pypi.org/simple/ --no-deps huitu_iot_protocol_rule==1.0.0

猜你喜欢

转载自blog.csdn.net/DearestFriend/article/details/108384481