Python发布Package到PyPi(发布自己的轮子)

Packaging Python Projects

文件目录结构

要上传到PyPi的目录结构
子目录PySearcher为你的PyPi项目名称

__init__.py代码

name = "PySearcher"  # 项目名称

setup.py代码

import setuptools


with open("README.md", "r", encoding="utf-8") as fh:
    long_description = fh.read()

setuptools.setup(
    name='PySearcher',
    version='0.0.6',
    description='Python search engine',
    long_description=long_description,
    long_description_content_type="text/markdown",
    keywords='code search tools',
    install_requires=[],
    packages=setuptools.find_packages(),
    author='Tyrone Zhao',
    author_email='[email protected]',
    url='https://github.com/Tyrone-Zhao/PySearcher',
    classifiers=[
        # 'Development Status :: 1 - Planning',
        # 'Development Status :: 2 - Pre-Alpha',
        # 'Development Status :: 3 - Alpha',
        # 'Development Status :: 4 - Beta',
        # 'Development Status :: 5 - Production/Stable'
        'Development Status :: 5 - Production/Stable',  # 当前开发进度等级(测试版,正式版等)
        'Intended Audience :: Developers',  # 模块适用人群
        'Topic :: Software Development :: Code Generators',  # 给模块加话题标签
        'License :: OSI Approved :: MIT License',  # 模块的license

        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: 3.7',
    ],
    project_urls={  # 项目相关的额外链接
        'Blog': 'https://blog.csdn.net/weixin_41845533',
    },
)

用户目录下创建.pypirc

Linux为~/.pypirc

[distutils]
index-servers=pypi

[pypi]
repository = https://upload.pypi.org/legacy/
username = 你的PyPi用户名
password = 你的PyPi密码

切换到setup.py同级目录后执行命令

python3 -m pip install --user --upgrade setuptools wheel
python3 -m pip install --user --upgrade twine
rm -r dist/* && python3 setup.py sdist bdist_wheel
twine upload dist/*

去PyPi查看项目

https://pypi.org/project/PySearcher/#description
查看已发布到PyPi的轮子

安装测试

pip3 install --upgrade 你的项目名称

猜你喜欢

转载自blog.csdn.net/weixin_41845533/article/details/86807649