很多朋友最近都在问这个问题,如何把自己封装的库传到PyPi官网开源给大家使用?
这里简单的讲一下整个过程,其实很简单。。。
1、封装一个完整的第三方库
a、编辑一个setup.py文档
如下(仅做参考):
from setuptools import (
find_packages,
setup,
)
is_py3 = sys.version_info[0] == 3
with open(join(dirname(__file__), 'VERSION.txt'), 'rb') as f:
version = f.read().decode('ascii').strip()
# 本地有一个VERSION.txt文件,文件控制每次发布的版本
install_requires = ['requests>=2.25.1',
'urllib3>=1.25.8',
'numpy>=1.18.1',
'pandas>=1.1.3',
'websocket-client>=1.1.0',
'json5>=0.9.1',
'crypto==1.4.1']
long_description = """
*** Quantitative Trading API is provided.
The correspondingly market data and trading is supported in A market.
see details in https://www.***.com/api
"""
setup(
name='**api_test',
version=version,
description='*** Quantitative Trading API',
classifiers=[],
keywords='*** HK Stock Quant Trading API',
author='*** FINANCIAL GROUP LTD.',
author_email='itsupport@***.com',
url='https://www.***.com/api',
license='Apache License 2.0',
packages=find_packages(exclude=[]),
package_data={'': ['*.*']},
include_package_data=True,
install_requires=install_requires,
long_description=long_description
)
b、库的其他文件
比如readme.md、**.py功能性文件
2、开始编译
a、打包
切换到项目的根目录、删除build、dist和xx.egg-info等文件
执行打包语句:python setup.py sdist bdist_wheel
此时,会重新生成build、dist和xx.egg-info等文件。
b、连接Pypi
执行语句:python -m twine upload --repository pypi dist/*
此时会调出,username:提示语,填入你在Pypi官网注册的账号,回车后,继续填入密码即可(密码是不显示的,注意别填重复了)。
PS:至此,完成了所有步骤。